Select
A field that opens a bottom sheet of options and shows the one the user picks. Long lists get a search field.
Installation
This also adds Bottom Sheet, which holds the options, and Search Field, for a searchable select.
Usage
- Tapping the field opens the sheet. Tapping an item selects it and closes the sheet.
- Tapping the dimmed backdrop, or dragging the sheet's handle down, closes it without a change.
- The field shows the selected item's
label, orplaceholderwhen nothing is selected. The selected item has a check mark. - The field is the same shape as an Input: 48px tall, on the same fill, so the two line up in a form. It dims while a finger is on it.
- The list scrolls once it's taller than 300 pixels. A searchable select's list fills the sheet instead.
With a label
label is shown above the field and as the sheet's title, and names the field for screen readers. A label of your own beside the field, such as a Label, isn't tied to it, so give the select an accessibility-label with the same text:
Search
Add searchable for a long list, such as time zones or countries:
- The sheet opens at full height, with a Search Field at the top. The keyboard rises below it.
- Typing hides every item whose
labeldoesn't contain the text. Case doesn't matter. emptyTextshows when nothing matches. It defaults toNo results.- The text clears when the sheet closes, so it opens on the full list next time.
- Bind
[(query)]to read or set the text.
Results of your own
Set [filter]="false" to show your own results for the text, such as suggestions from a server:
See HTTP requests for httpResource on Lynx.
The field shows the chosen item's label. Once the item is gone from the list, it shows the value itself. Keep the chosen result among the items to keep its label in the field.
Icons
Put content in an item, such as an Icon, and it goes before the label. Mark content leading on the select itself to show it in the field, before the text:
Accessibility
- The field is one button to VoiceOver and TalkBack, named by
label(oraccessibility-label), with the chosen item's label, or the placeholder, as its value: VoiceOver says "Country, Germany, button". Without either, the field's name is the text it shows. - A disabled field is dimmed to VoiceOver as well.
- Each item is a button named by its
label, and the chosen one isselected, as its check mark shows. - Content in the field and the items, such as icons, isn't read. The label says what they mean.
So a spec finds them by role:
Disabled
A disabled select dims and doesn't open.
Open from code
UiSelect has public open(), close() and toggle() methods. Get it with viewChild(UiSelect) and call them from a handler. open() and toggle() do nothing while disabled.
Forms
value is a model(), so it works with every Angular forms API:
The sheet closing marks the field touched, whether an item was chosen or not. UiSelect implements Signal Forms' FormValueControl. See Forms.
API
UiSelect
UiSelectItem
No outputs. Content inside the item, such as an icon, goes before its label.
Related
- Multi Select: pick any number of options
- Radio Group: show every option on screen
- Bottom Sheet: the panel the options open in
- Dialogs and overlays
