Summary 💡
I tried to search from issues whether this would've been discussed already, but wasn't able to found one, so here goes:
Would it make sense to provide a prop for Autocomplete component to display a fixed "Select all" option in the options drop-down, if multiple is set for the component?
Examples 🌈
CodeSandbox demo, with ListBox customization:
https://codesandbox.io/s/thirsty-moon-9egd9
Motivation 🔦
The requirement I'd need to fulfill, is that every selectable option should be easily selected "via one click", and, the ability to do so should exist in close vicinity of the Autocomplete component (= in the options ListBox)
Currently, this needs customization from the developer, and seems that there are many ways to achieve the wanted behavior. But gut feeling is, that each customization is prone to contain some amount of smelling hacks (might also be, that I've missed some key factors upon implementations).
Some technical requirements, I came up with for the "select all" enabled Autocomplete:
- separate the "select all" from other actual "options" (for me it seems clearer to have that distinction)
- use the
Autocomplete component, instead of useAutocomplete hook, as the Autocomplete component provides 90% of other functionalities out of the box (which is more than enough for me)
- display "select all" always on top, outside of the scrolling content
I've experimented this, by providing a customized ListBox for the Autocomplete component, that always renders some "select all" component on top, and props.children after that.
This mostly works, but the "select all" cannot be focused via keyboard navigation, as it's missing the tabindex and the data-option-index attributes --> data-option-index is dynamically generated, and I wouldn't want to "regenerate" them. Why I'd need to regenerate them? Because I'd like to have the "select all" option not to be included in the options, and the attributes are generated for the options.
Summary 💡
I tried to search from issues whether this would've been discussed already, but wasn't able to found one, so here goes:
Would it make sense to provide a prop for
Autocompletecomponent to display a fixed "Select all" option in the options drop-down, ifmultipleis set for the component?Examples 🌈
CodeSandbox demo, with ListBox customization:
https://codesandbox.io/s/thirsty-moon-9egd9
Motivation 🔦
The requirement I'd need to fulfill, is that every selectable option should be easily selected "via one click", and, the ability to do so should exist in close vicinity of the Autocomplete component (= in the options ListBox)
Currently, this needs customization from the developer, and seems that there are many ways to achieve the wanted behavior. But gut feeling is, that each customization is prone to contain some amount of smelling hacks (might also be, that I've missed some key factors upon implementations).
Some technical requirements, I came up with for the "select all" enabled Autocomplete:
Autocompletecomponent, instead ofuseAutocompletehook, as theAutocompletecomponent provides 90% of other functionalities out of the box (which is more than enough for me)I've experimented this, by providing a customized ListBox for the
Autocompletecomponent, that always renders some "select all" component on top, andprops.childrenafter that.This mostly works, but the "select all" cannot be focused via keyboard navigation, as it's missing the
tabindexand thedata-option-indexattributes --> data-option-index is dynamically generated, and I wouldn't want to "regenerate" them. Why I'd need to regenerate them? Because I'd like to have the "select all" option not to be included in theoptions, and the attributes are generated for theoptions.