The Autocomplete groups its options when you pass getOptionGroup, a function that returns an option’s group name or undefined. The name is also the group’s label. Options stay one flat list, and a hairline separates the sections.

Nothing selected.

Open the picker, then untick “Sort by region” and open it again: the groups change order, but each region’s countries stay together.

Order

getOptionGroup does not sort anything. The order comes from options:

  • Groups appear in the order of their first option. Sort the options by group first, as the demo does, to choose the group order.
  • An option joins its group wherever it sits in the list, so a group’s options need not be next to each other.
  • Options with no group form one unlabelled section, placed where the first of them appears. In the demo that is Australia.
  • A group the search empties disappears, with its label and its separator.

The keyboard follows the order on screen. The arrow keys, Home, End, PgUp, PgDn, typeahead and autoHighlight move through the options only. Labels and separators are never highlighted.

Remote pages and virtual lists

With remote options, each new page joins the groups already on screen. A page that brings more countries from Europe adds them under the existing Europe label, not under a second one.

VirtualAutocomplete renders labels and separators as rows of their own. Their heights come from virtual.groupLabelSize (28 by default) and virtual.separatorSize (9). Change them if your GroupLabel or Separator slot is taller. When a label scrolls out of view, the list keeps a hidden copy of it, so the group still has a name.

Changing the parts

Three slots draw the groups:

  • Group wraps one group’s options.
  • GroupLabel is the label. It receives hidden for the virtual list’s hidden copy, so pass that on.
  • Separator is the line between sections.

In your own layout, the compound parts Autocomplete.Group, Autocomplete.GroupLabel and Autocomplete.Separator render the same parts; see compound parts. The headless useAutocomplete returns sections and the matching prop getters. The adapters draw groups with each library’s own label and divider.

Accessibility

Each group has role="group" and is named by its label through aria-labelledby. The label itself has role="presentation", so it is not read as an extra item. The separator is hidden from assistive technology, because a listbox may only contain options and groups.