Skip to content

[autocomplete] Option to select all options if multiple selections enabled #21211

@vileppanen

Description

@vileppanen
  • I have searched the issues of this repository and believe that this is not a duplicate.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: autocompleteChanges related to the autocomplete. This includes ComboBox.waiting for 👍Waiting for upvotes. Open for community feedback and needs more interest to be worked on.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions