Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filters - Clearing autocomplete filter #1351

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from

Conversation

avightclav
Copy link

…er than the 'X' button doesn't clear the selected value.

KevinVandy#1100
Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
material-react-table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 7:32pm
material-react-table-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 7:32pm

…alue

(aka fixed bug that I introduced myself in previous commit)
@avightclav
Copy link
Author

So, what is done in this PR:

  1. Input control. Made Autocomplete's input value to be controlled through inputValue/onInputChange props as shown in docs . It allows component to correctly process external clearing of values. Correctly means clear button is not shown and full list of options is shown if inputValue and value were cleared. It doesn't process it correctly if input value passed directly to TextField component as I've tested.
  2. State variable for input value. Utilized filterValue (MRT_FilterTextField's internal state variable) to control exclusively the input value of Autocomplete component. I thought of creating separate state variable for that so I won't have to explicitly typecast, but I saw that the current codebase already has a lot of type casting.
  3. Actually clear Autocomplete's state variables after column's filterValue has been cleared. Added branch in handleClear to actually handle column's filterValue clearing.
  4. Initialization. Initial column's filterValue can be one of:
    1. string value from filterValue
    2. any type value from autocompleteValue
    3. unknown value from user provided filters state (not product of MRT_FilterTextField component lifecycle)

And we can't distinguish between them on initialization so we initialize filterValue to column's filterValue if it is string just because it is safe to. But it doesn't matter because non-null initialized autocompleteValue takes precedence for rendering label in Autocomplete.
⚠️ So it's up to client to implement getOptionLabel that returns correct label from initial column's filterValue.
But that is not what I've added, it's the way it worked before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant