Skip to main content

Select

Library
UDS Base
Repository
github.com/telus/universal-design-system
Package
npmjs.com/package/@telus-uds/components-base
Package version
1.6.1
Loading...

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 or ButtonGroup.
  • 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.

Loading...

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

NameTypeDefaultDescription
initialValuestringInitial value for the uncontrolled version.
valuestringCurrent value to be set as selected.
onChangefuncCallback to be called when the value changes.
childrencustomAn array of items or item groups to be used as options.
inactiveboolWhether the select is disabled.
readOnlyboolWhether the select is read-only.
placeholderstringA placeholder to provide instructions (such as "Please select...") as an unselectable option
tokenscustomSystem tokens prop, see tokens for more details
variantobjectOfSystem variant prop, see variants for more details
testIDstringDedicated ID for testing.