-
|
I'm trying to build a component using the Select + Autocomplete example from the new docs (or a similar one that Devon also shared on X awhile back), with one small addition - I also need to have "Select All" and "Select None" buttons added within the Popover to quickly select / deselect the options. Here's an example of what I mean: https://stackblitz.com/edit/6ppf3ucz?file=src%2FExample.tsx I can get it working just fine with selecting ALL items in the collection. However, when the list is filtered using Autocomplete, I need the "Select All" button to select only all visible items (ie. filtered ones), and not all of the items in the original list. Is this at all possible with the current components? Is this stored in a particular context that I can read from? I've tried using Would appreciate some help on how to tackle this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
The ListBox actually handles its own filtering based on the filter function and value provided on the Autocomplete context. This is so that Autocomplete doesn't need to know about the structure of the data and we don't need to pass the collection state up, which would be a little reversed from the usual data flows down approach. Assuming you are declaring your items as a data object, you could use the same filter function that you send to the autocomplete to determine what "all" currently is during the input's onChange. |
Beta Was this translation helpful? Give feedback.
So I think I may have figured this out. Would appreciate a sanity check though.
Here's the updated demo: https://stackblitz.com/edit/6ppf3ucz?file=src%2FSelectButtons.tsx
I'm using your original idea of applying the same
filterfunction on the data set as what's used in Autocomplete, but instead of a user having to pass it in, I'm just baking that into component logic.Here is the code: