What the component guarantees
- A combobox and a listbox. The trigger is a
<button role="combobox">witharia-expanded,aria-haspopup="listbox"and, while open,aria-controlspointing at the list. The list isrole="listbox"(witharia-multiselectableformultiple), groups arerole="group", and each option isrole="option"witharia-selectedandaria-disabled. - The label is wired.
labelrenders anNbLabelwhoseformatches the trigger's id, so clicking the label opens the control and a reader names it. Influidthe label is text inside the trigger, with the id{id}-label, and the trigger points at it witharia-labelledby, so the label stays the name wherever it sits and the trigger's text is the value. - Validation is announced and linked. With
error, the trigger carriesaria-invalid="true". The visible message (error, warning or helper, in that order) has its own id ({id}-error,{id}-warning,{id}-helper) and the trigger points at it witharia-describedby. A message present on first render is read when the trigger takes focus and is not shouted on load. An error that appears or changes later mounts withrole="alert", a warning withrole="status". With your own#trigger,attrscarriesaria-invalidtoo. - The reader follows the highlight. Without
searchable, focus stays on the trigger while the list is open, and the trigger points at the highlighted option witharia-activedescendant. Withsearchable, focus moves into the search box, which is named bysearch-placeholderand carriesaria-activedescendantinstead, and the trigger leaves it off. Every option has its own id, so the reference always resolves. A test can find a field's list through the trigger'saria-controlsrather than guessing its id. - Clear is its own control. With
clearable, the clear button is a separateNbButtonnext to the trigger, named by itslabel(which is also its tooltip) and drawing the shared focus ring, reached with Tab after it. Pressing it never opens the list, and focus goes back to the trigger. - Focus comes back. Closing the list returns focus to the trigger. Inside an
NbModal, the teleported list is part of the dialog for the focus trap. - Tested in
tests/Select.test.tsandtests/fieldValidationAria.test.ts, and by axe intests/axe.test.ts.
Keyboard
| Key | Action |
|---|---|
| Enter / Space / ↓ | On the trigger, opens the list |
| ↑ ↓ | Moves the highlight, skipping disabled options |
| Home / End | First or last option |
| Enter / Space | Selects the highlighted option |
| Esc / Tab | Closes the list |
With searchable, typing narrows the list, Enter picks the highlighted match, and Space is part of the search, not a choice.
What you own
- A label. Without
label, a#labelslot or anaria-label, the trigger is named only by its current value. - Error text that says how to fix it. "Choose a country" rather than "Invalid".
- Not opening a list nobody asked for. Opening the list programmatically (the exposed
open()) moves focus into it; only do that in response to the user.
Known gaps
- No manual screen reader pass has been recorded for this component.
- In forced-colours mode the highlighted option and the default
fillselection are background washes, which the browser discards. Withselected-mark="check"the selection keeps its glyph; the highlight does not survive either way.