Docs
Advanced
Roles

Roles

The following sections describe the various element roles involved in building the multi-select autoccomplete component.

Overview

Consider the following schema. The autocomplete consists of 6 basic building blocks:

  1. A value container with a delete button to remove the selected value.
  2. An input field element that is used to enter the search query.
  3. A button to toggle the listbox popover.
  4. A listbox popover that contains the list of options.
  5. An option element that represents a single option.
  6. A wrapper element that contains the entire autocomplete component.
Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper
Schematic overview over the component roles. Hover the role name to highlight the components.

We'll cover the roles in detail in the following sections.

Value

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The value container is has no special role and is simply a container for the selected value and a delete button.

The delete button and the value container are not focusable. By clicking on the left and right arrow keys, the user can navigate through the selected values, highlighting the next or previous value. By clicking the backspace key, the user can delete the currently highlighted value. If the backspace key is pressed in the empty input field, the user will delete the last value in the list.

Input

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The input serves as a search field for the list of options. The input is focusable and the user can type in a search query. By entering a search query, the input opens the listbox popover and filters the list of options.

Button

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The button is used to toggle the listbox popover. The button is not focusable and the user can toggle the listbox popover by pressing the enter or space key.

Popover

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The popover is a container for the list of options. The user can navigate through the list of options by pressing the up and down arrow keys. The popover is closed when

  • the user presses the Esc key or
  • clicks outside the wrapper element or
  • selects an option either by clicking on it or by pressing the Enter key.

Option

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The option represents a single option in the list of options. The option is not focusable. The user can select an option by pressing the Enter key. The option is also selectable by clicking on it.

To navigate between options, the user can press the up and down arrow keys. Pressing the up arrow key, the previous option is highlighted. When the user presses the down arrow key, the next option is highlighted.

Wrapper

Value & Delete Buttonwhite"Input FieldPopover buttonPopoverOptionWrapper

The wrapper bundles all elements together and acts as the root element of the autocomplete component. It binds all click and keydown handlers for controlling the autocomplete behavior.

The wrapper should hold the visual indication of the focus state, for example via a style change using the :focus-within pseudo-class.

The wrapper gets its properties from the getWrapperProps function.