---
title: Select
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Select } from '@telus-uds/components-web'
import { Select as BaseDocs } from 'docs/@telus-uds/components-base'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'
import AdditionalVariants from '../../src/components/Variants/Select'

# Select

<LibraryInfo figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D455%253A32" />

```jsx live
<Select
  label="Label"
  hint="This is the hint (below)"
  hintPosition="below"
  tooltip="This is the tooltip content"
  feedback="Some instructional feedback"
>
  <Select.Item value="root-item-1">Root item 1</Select.Item>
  <Select.Item value="root-item-2">Root item 2</Select.Item>
  <Select.Group label="Group label">
    <Select.Item value="group-item-1">Group item 1</Select.Item>
    <Select.Item value="group-item-2">Group item 2</Select.Item>
  </Select.Group>
  <Select.Item value="root-item-3">Root item 3</Select.Item>
</Select>
```

## Introduction

Select is a basic form single-choice select component. You can use it in forms or individually to receive user's input.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## 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.

```jsx live
<>
  <Select label="Success" feedback="He chose wisely" validation="success" initialValue="good">
    <Select.Item value="good">Good</Select.Item>
    <Select.Item value="bad">Bad</Select.Item>
  </Select>

  <Select label="Error" feedback="He chose poorly" validation="error" initialValue="bad">
    <Select.Item value="good">Good</Select.Item>
    <Select.Item value="bad">Bad</Select.Item>
  </Select>
</>
```

### Assigning an ID

The `Select` component provides the capability to specify a custom identifier through the use of the `nativeID` property.

```jsx live
<Select nativeID="My custom ID">
  <Select.Item value="one">One</Select.Item>
  <Select.Item value="two">Two</Select.Item>
</Select>
```

### 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

<AvailableOnBoth />

Keep in mind though that grouping does not work on native platforms - the grouped items will be shown at the same
level as the non-grouped items.

## Props

### Select

<PropsTable base={BaseDocs} />

### Select.Item

<PropsTable base={BaseDocs.Item} />

### Select.Group

<PropsTable base={BaseDocs.Group} />

## Tokens

<TokensTable base={BaseDocs} component="Select" />

## Variants

<NoStylisticVariants />

## Additional Variants

Please note that if you are building an application that is brand specific you can use these variants.
These brand specific variants are defined in the community themes and you'd need to install those relevant packages and use `mergeThemes` from `@telus-uds/system-constants` to merge the brand specific theme with the core theme.

Here's an example of how to update the application's entry point to merge the Koodo community theme with the core theme:

```jsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BaseProvider } from '@telus-uds/components-base'
import themeKoodo from '@telus-uds/theme-koodo'
import themeKoodoCommunity from '@telus-uds/themes-community.theme-koodo'
import { mergeThemes } from '@telus-uds/system-constants'
import App from './App'
const rootElement = document.getElementById('root')
const root = createRoot(rootElement)
root.render(
  <StrictMode>
    <BaseProvider defaultTheme={mergeThemes(themeKoodoCommunity, themeKoodo)}>
      <App />
    </BaseProvider>
  </StrictMode>
)
```

<AdditionalVariants />

## Feedback

<Feedback component="Select" />
