Create

Form

Native Select

Copy page View as Markdown Open in ChatGPT Open in Claude

A styled native select element: the browser shows its own list of options.

Usage#

app.component.ts
import { WdsNativeSelectComponent } from '@wds/angular/native-select';

Examples#

Default#

Write <option> elements inside. An option with an empty value works as a prompt; disabled options cannot be picked.

Groups#

<optgroup> puts options under a heading.

Size#

size="sm" makes the field 28px high instead of 32px.

Field#

In wds-field the label and description name and describe the select. Without a matching value the first option is selected.

Region Trains in this region appear first.

Disabled#

Invalid#

invalid draws a red border and sets aria-invalid; in wds-field set invalid on the field.

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsSelectField connects the select to [formField] (a string).

ClassSubmit

Submitted: —

Template-driven#

WdsSelectValueAccessor makes ngModel work on wds-native-select.

ClassSubmit

Submitted: —

Reactive forms#

The same WdsSelectValueAccessor works with formControl and formControlName.

ClassSubmit

Submitted: —

API References#

wds-native-select#

A styled native <select>: the browser's own list opens, which suits mobile devices and long, simple lists. Write <option> and <optgroup> elements inside; the element copies them into its <select> and follows their changes. It works in a <form> and with wds-field. Without a matching value the first option is selected (or the one with selected), as in a native <select>. For a list with search, icons or several values use wds-select or wds-combobox.

Attributes

AttributeTypeDefaultDescription
valuestring''Value of the selected option.
namestring''Field name in the form.
sizeWdsNativeSelectSize'default'Field height: sm 28px, default 32px.
disabledbooleanfalseDisables the field and excludes it from form submission.
requiredbooleanfalseAn option with a non-empty value is required for the form to be valid.
invalidbooleanfalseError state: red border and aria-invalid.
autocompletestring''Native autocomplete hint, e.g. country.

Events

EventDescription
wds-changeCustomEvent<WdsNativeSelectChangeDetail>The user picked an option.

Methods

MethodDescription
formResetCallback()
formDisabledCallback(disabled: boolean)
formStateRestoreCallback(state: string | File | FormData | null)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

Slots

SlotDescription
(default)<option> and <optgroup> elements. They are not shown themselves: the native <select> shows their copies.

CSS parts (::part)

PartDescription
controlThe native <select>.
iconThe chevron.

Accessibility#

Screen reader#

Inside is a native <select>: screen readers announce it as a combo box or pop-up button with the selected option, and the browser draws the list.

Give the select a name: wds-field-label in wds-field, or aria-label on the element. A prompt option with an empty value is not a name.

<optgroup> labels are read with their options. invalid, required and disabled reach the native <select>; in a form the value is submitted under name, and a reset restores the option with selected.

Keyboard support#

KeyFunction
TabMoves focus to the select.
ArrowDownArrowUpChanges the option (Windows, Linux) or opens the list (macOS).
SpaceAlt + ArrowDownOpens the list.
EnterPicks the highlighted option in an open list.
EscapeCloses the list without changing the value.
A–ZMoves to the next option starting with the typed letters.
Footer