Select
- Library
- UDS Base
- Repository
- github.com/telus/universal-design-system
- Package
- npmjs.com/package/@telus-uds/components-base
- Package version
- 1.6.1
Introduction
import { Select } from '@telus-uds/components-base'
Select is a basic form single-choice select component. You can use it in forms or individually to receive user's input.
Guidance
- Include a
placeholder
to provide instructions such as "Please select..." as an unselectable option (recommended) - Use when options are between 7-15 (recommended)
- For options are 6 and under, use
Radio
groups orButtonGroup
. - For options 15 and above, look for alternatives (e.g grouping into categories, or input field with auto-complete etc.)
Controlled component
If it is required that the state of the Select be controlled by the application or other external methods,
value
and onChange
props must be passed to the Select.
If the Select value should not be changed by user input, a readOnly
prop must be provided.
Uncontrolled component
If it is not necessary to control the Select state, you can create one without a value prop.
In this case its value can be accessed within the onChange
callback. Use the initialValue
prop to set the
default value for an uncontrolled Select.
Getting feedback for entered values
Use the feedback
prop to give the user feedback regarding their selection.
You can affirm that the user's selection was correct, or highlight errors that must be corrected, using the validation
prop.
Keep feedback text as brief as possible, should be limited to text and links.
Using a tooltip
When a more in-depth explanation is needed to fill out a Select properly, the tooltip prop may be used.
Grouping options
Select supports option groups. Use a Select.Group component to render an <optgroup>
element with its items.
Accessibility
Select component uses label
prop to set the accessibility label attribute. It also uses hint
or feedback
prop
(depending on the validation results) to set the accessibility hint and described by (aria-describedby
) attributes.
Platform considerations
Keep in mind that grouping does not work on native platforms - the grouped items will be shown at the same level as the non-grouped items.
Props
Name | Type | Default | Description |
---|---|---|---|
initialValue | string | Initial value for the uncontrolled version. | |
value | string | Current value to be set as selected. | |
onChange | func | Callback to be called when the value changes. | |
children | custom | An array of items or item groups to be used as options. | |
inactive | bool | Whether the select is disabled. | |
readOnly | bool | Whether the select is read-only. | |
placeholder | string | A placeholder to provide instructions (such as "Please select...") as an unselectable option | |
tokens | custom | System tokens prop, see tokens for more details | |
variant | objectOf | System variant prop, see variants for more details | |
testID | string | Dedicated ID for testing. |