Usage
Select lets users choose a single option from a menu. Consider using it when you have five or more options to choose from. Place <option> elements in the default slot, and use value to set the initial selection. For a small number of mutually exclusive options, consider Radio buttons instead.
The select renders its built-in label, hint and error on its own. Wrapped in a Field, the Field takes over with a Field Label, Field Description and Field Error, and the built-in versions step aside automatically.
import "@nordhealth/components/lib/Select"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"
Standalone or inside a Field
Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:
Examples
Basic
A select with a connected Field Label and a list of <option> choices.
Autocomplete
Set autocomplete to let the browser suggest and fill a previously entered value.
Sizes
Use the size attribute to render a small, medium (default) or large select.
Hint
Add a Field Hint to give the user extra guidance about the field.
Required
Set required on the Field Label to show the required indicator and mark the control required.
Hidden label
To hide the label visually while keeping it available to assistive technology, connect a Field Label with for and visually hide it.
Custom width
Constrain or expand the select by setting a custom width on the control.
Custom button style
Customise the trigger appearance with CSS custom properties or parts.
Custom icon
Replace the default chevron with a custom icon via the icon slot.
In a form
Use the select inside a <form> to submit its value alongside other fields.
Placeholder
Use placeholder to prompt the user to make a choice before any option is selected. It is not a replacement for a Field Label.
Error
Show validation with a Field Error and mark the Field invalid.
Disabled
A disabled select cannot be focused or changed and is excluded from form submission.
Expand
Use expand to make the select fill the width of its container.
RTL
Select follows the document or container direction. Toggle the direction to see the layout mirror.
Accessibility
- Always give the select an accessible name with a Field Label connected via
for. - Convey validation with a Field Error rather than colour alone — it is associated with the select and announced to assistive technology.
- Mark required fields by setting
requiredon the Field Label; it shows the indicator and marks the control required. - Give every
<option>clear, descriptive text, and use aplaceholderrather than an empty option to prompt for a choice. - For a small number of mutually exclusive options, consider Radio buttons instead, which expose all choices at once.
API reference
Select
Select lets users choose one option from an options menu. Consider using select when you have 5 or more options to choose from.
<nord-select></nord-select>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
expand | expand | Controls whether the select expands to fill the width of its container. | boolean | false |
size | size | The size of the component. | 's' | 'm' | 'l' | 'm' |
placeholder | placeholder | Placeholder text to display within the control. | string | undefined | — |
required | required | Determines whether the control is required or not.
A required control is announced as such to assistive technology and, inside
a <nord-field>, drives the required indicator on the <nord-field-label>.
When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors. | boolean | false |
autocomplete | autocomplete | Specifies the data type of the field, so that the browser may attempt to fill out the field automatically on behalf of the user. | AutocompleteAttribute | 'off' |
disabled | disabled | Makes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies. | boolean | false |
name | name | The name of the form component. | string | undefined | — |
value | value | The value of the form component. | string | '' |
form | form | Gets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form. | HTMLFormElement | null | — |
Field properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
label | label | Label for the control. Ignored when the control is wrapped in a
<nord-field>, which provides the label via <nord-field-label>. | string | '' |
hint | hint | Optional hint text shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-description>. | string | undefined | — |
hintBelow | hint-below | Renders the hint below the control and any error instead of below the label. | boolean | false |
hideLabel | hide-label | Visually hide the label, but still expose it to assistive technologies. | boolean | false |
error | error | Optional error shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-error>. | string | undefined | — |
hideRequired | hide-required | Visually hide the required indicator, but still expose the required state to assistive technologies. | boolean | false |
Slots
| Slot name | Description |
|---|---|
Default slot | Default slot for holding |
label | Use when a label requires more than plain text. |
hint | Use when a hint requires more than plain text. |
error | Optional slot that holds error text for the input. |
icon | Used to place an icon at the start of select. |
Methods
| Method name | Parameters | Description |
|---|---|---|
focus(options?: FocusOptions) => void | options: An object which controls aspects of the focusing process. | Programmatically move focus to the component. |
blur() => void | N/A | Programmatically remove focus from the component. |
click() => void | N/A | Programmatically simulates a click on the component. |
| Event | Detail Type | Description |
|---|---|---|
input | NordEvent | Fired as the user types into the input. |
change | NordEvent | Fired whenever the input's value is changed via user interaction. |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-select-block-size | Controls the block size, or height, of the select using our spacing tokens. | var(--n-space-xl) |
--n-select-inline-size | Controls the inline size, or width, of the select. | fit-content |
--n-label-color | Controls the text color of the label, using our color tokens. | var(--n-color-text) |
Dependencies
This component is internally dependent on the following components:
- <nord-button>
Button
Buttons are used for interface actions. Primary style should be used only once per section for main call-to-action, while other styles can appear more frequently.
- <nord-icon>
Icon
Icons are used to provide additional meaning or in places where text label doesn’t fit. Icon component allows you to display an icon from the Nordicons library.
Design guidelinesFor designers
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
- Use to let a user choose one option from an options menu.
- Use when you have more than 6 options to choose from.
- Use when you don’t know how many options there will be.
- Use hint text and placeholder to provide additional, non-critical instructions.
Don’t
- Don't use a select if you have less than 6 options to choose from. Consider using segmented control or radio components instead, if you have enough space to allow it.
Hint placement
Hint text is rendered above the control by default to preserve existing behavior for current consumers. Use the hint-below property to opt in to rendering the hint below the control and any error.
This is a non-breaking rollout for teams adopting the new layout gradually. Existing integrations keep the current placement unless hint-below is explicitly set.
Content guidelines
Select labels act as a title for the select field. Labels should typically be short and in noun form:
When writing select labels, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):
Do not use colons in select labels: