# Select

> A closed, scannable list that chooses one or more values without text entry.

```tsx title="hero.tsx"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'

const languages = [
  { label: 'English', value: 'en-US' },
  { label: '简体中文', value: 'zh-Hans' },
  { label: '日本語', value: 'ja-JP' },
  { label: 'Español', value: 'es-ES' },
  { label: 'Français', value: 'fr-FR' },
  { label: 'Deutsch', value: 'de-DE' },
] as const

type LanguageCode = (typeof languages)[number]['value']

export function SelectHeroDemo() {
  return (
    <Select<LanguageCode> items={languages} defaultValue="en-US">
      <div className="flex w-full max-w-64 flex-col gap-1">
        <SelectLabel>Response language</SelectLabel>
        <SelectTrigger>
          <SelectValue<LanguageCode>
            render={(props, state) => <span {...props} lang={state.value ?? undefined} />}
          />
        </SelectTrigger>
      </div>
      <SelectContent>
        {languages.map((language) => (
          <SelectItem<LanguageCode> key={language.value} value={language.value}>
            <SelectItemText lang={language.value}>{language.label}</SelectItemText>
            <SelectItemIndicator />
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  )
}
```

## Usage guidelines

- Use `Select` to choose from a closed list the user can scan. Use `Combobox` when the list needs search, `Autocomplete` for free text with suggestions, and `RadioGroup` or `SegmentedControl` when every option should stay visible.
- Give the trigger an accessible name: a visible `SelectLabel`, a field label, or `aria-label` when the surrounding layout already labels it visually.
- Pass `items` to the root so `SelectValue` renders the label of the selected value, including before the popup first opens.
- Keep the caller's value type. `Select<Value>` infers it from `value`, `defaultValue` and `items`; do not widen a union of IDs to `string`.
- `SelectContent` is at least as wide as the trigger and clamps to the viewport with Base UI's `--anchor-width` and `--available-width`. Do not replace that sizing with a fixed width.

## Anatomy

```tsx
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectGroupLabel,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'
```

```tsx
<Select>
  <SelectLabel />
  <SelectTrigger>
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectItem>
      <SelectItemText />
      <SelectItemIndicator />
    </SelectItem>
    <SelectSeparator />
    <SelectGroup>
      <SelectGroupLabel />
      <SelectItem />
    </SelectGroup>
  </SelectContent>
</Select>
```

`SelectContent` bundles the portal, positioner, popup and scrollable list. Compose `SelectPortal`, `SelectPositioner`, `SelectPopup` and `SelectList` directly only when a surface needs positioning beyond `side`, `align` and their offsets.

## Examples

### Multiple selection

Pass `multiple` to choose more than one option from the list; the popup stays open as you toggle items. Type `SelectValue<Value, true>` to format the read-only array and provide placeholder text when nothing is selected.

```tsx title="multiple.tsx"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'

const fileTypes = [
  { label: 'PDF', value: 'pdf' },
  { label: 'Markdown', value: 'markdown' },
  { label: 'Word (DOCX)', value: 'docx' },
  { label: 'CSV', value: 'csv' },
  { label: 'Plain text', value: 'txt' },
  { label: 'Images', value: 'image' },
  { label: 'Audio', value: 'audio' },
] as const

type FileType = (typeof fileTypes)[number]['value']

const fileTypeLabels = Object.fromEntries(fileTypes.map((item) => [item.value, item.label])) as {
  [Key in FileType]: string
}

function renderSelected(value: readonly FileType[] | null) {
  if (!value || value.length === 0) return 'Select file types'
  const first = fileTypeLabels[value[0]!]
  return value.length === 1 ? first : `${first} (+${value.length - 1} more)`
}

export function SelectMultipleDemo() {
  return (
    <Select<FileType, true> multiple items={fileTypes} defaultValue={['pdf', 'markdown']}>
      <div className="flex w-full max-w-64 flex-col gap-1">
        <SelectLabel>Allowed file types</SelectLabel>
        <SelectTrigger>
          <SelectValue<FileType, true>>{renderSelected}</SelectValue>
        </SelectTrigger>
      </div>
      <SelectContent>
        {fileTypes.map((fileType) => (
          <SelectItem<FileType> key={fileType.value} value={fileType.value}>
            <SelectItemText>{fileType.label}</SelectItemText>
            <SelectItemIndicator />
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  )
}
```

### Sizes

`SelectTrigger` supports `small`, `medium` (default) and `large` sizes.

```tsx title="sizes.tsx"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'

const logLevels = [
  { label: 'Debug', value: 'debug' },
  { label: 'Info', value: 'info' },
  { label: 'Warning', value: 'warning' },
  { label: 'Error', value: 'error' },
  { label: 'Fatal', value: 'fatal' },
  { label: 'Off', value: 'off' },
]

const sizes = [
  { size: 'small', label: 'Small', defaultValue: 'warning' },
  { size: 'medium', label: 'Medium', defaultValue: 'info' },
  { size: 'large', label: 'Large', defaultValue: 'debug' },
] as const

export function SelectSizesDemo() {
  return (
    <div className="flex w-full max-w-64 flex-col gap-4">
      {sizes.map((entry) => (
        <Select key={entry.size} items={logLevels} defaultValue={entry.defaultValue}>
          <div className="flex flex-col gap-1">
            <SelectLabel>{entry.label}</SelectLabel>
            <SelectTrigger size={entry.size}>
              <SelectValue />
            </SelectTrigger>
          </div>
          <SelectContent>
            {logLevels.map((level) => (
              <SelectItem key={level.value} value={level.value}>
                <SelectItemText>{level.label}</SelectItemText>
                <SelectItemIndicator />
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      ))}
    </div>
  )
}
```

### Groups and disabled items

Group related items under a `SelectGroupLabel` and divide groups with `SelectSeparator`. A disabled item stays visible and can be highlighted, but not selected.

```tsx title="groups.tsx"
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectGroupLabel,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'
import * as React from 'react'

type ModelOption = {
  label: string
  value: string
  disabled?: boolean
}

const providers: { name: string; models: ModelOption[] }[] = [
  {
    name: 'OpenAI',
    models: [
      { label: 'GPT-5', value: 'gpt-5' },
      { label: 'GPT-5 mini', value: 'gpt-5-mini' },
      { label: 'o4-mini', value: 'o4-mini' },
    ],
  },
  {
    name: 'Anthropic',
    models: [
      { label: 'Claude Opus 4', value: 'claude-opus-4' },
      { label: 'Claude Sonnet 4', value: 'claude-sonnet-4' },
      { label: 'Claude Haiku (deprecated)', value: 'claude-haiku', disabled: true },
    ],
  },
  {
    name: 'Google',
    models: [
      { label: 'Gemini 2.5 Pro', value: 'gemini-2.5-pro' },
      { label: 'Gemini 2.5 Flash', value: 'gemini-2.5-flash' },
    ],
  },
]

const items = providers.flatMap((provider) => provider.models)

export function SelectGroupsDemo() {
  return (
    <Select items={items} defaultValue="gpt-5">
      <div className="flex w-full max-w-64 flex-col gap-1">
        <SelectLabel>Default model</SelectLabel>
        <SelectTrigger>
          <SelectValue />
        </SelectTrigger>
      </div>
      <SelectContent>
        {providers.map((provider, index) => (
          <React.Fragment key={provider.name}>
            {index > 0 && <SelectSeparator />}
            <SelectGroup>
              <SelectGroupLabel>{provider.name}</SelectGroupLabel>
              {provider.models.map((model) => (
                <SelectItem key={model.value} value={model.value} disabled={model.disabled}>
                  <SelectItemText>{model.label}</SelectItemText>
                  <SelectItemIndicator />
                </SelectItem>
              ))}
            </SelectGroup>
          </React.Fragment>
        ))}
      </SelectContent>
    </Select>
  )
}
```

### Typed controlled value

Control the value with `value` and `onValueChange` when another part of the page reads it. The value keeps its domain type.

```tsx title="typed-value.tsx"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'
import * as React from 'react'

const regions = [
  { label: 'US East (Virginia)', value: 'us-east' },
  { label: 'US West (Oregon)', value: 'us-west' },
  { label: 'Europe (Frankfurt)', value: 'eu-central' },
  { label: 'Europe (Ireland)', value: 'eu-west' },
  { label: 'Asia Pacific (Tokyo)', value: 'ap-northeast' },
  { label: 'Asia Pacific (Singapore)', value: 'ap-southeast' },
] as const

type Region = (typeof regions)[number]['value']

export function SelectTypedValueDemo() {
  const [region, setRegion] = React.useState<Region>('us-east')
  const regionLabel = regions.find((item) => item.value === region)?.label

  return (
    <div className="flex w-full max-w-64 flex-col gap-2">
      <Select<Region>
        items={regions}
        value={region}
        onValueChange={(value) => {
          if (value) setRegion(value)
        }}
      >
        <div className="flex flex-col gap-1">
          <SelectLabel>Deployment region</SelectLabel>
          <SelectTrigger>
            <SelectValue />
          </SelectTrigger>
        </div>
        <SelectContent>
          {regions.map((item) => (
            <SelectItem<Region> key={item.value} value={item.value}>
              <SelectItemText>{item.label}</SelectItemText>
              <SelectItemIndicator />
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
      <p aria-live="polite" className="system-xs-regular text-text-tertiary">
        Deploying to {regionLabel} (<code className="font-mono text-text-secondary">{region}</code>)
      </p>
    </div>
  )
}
```

## Keyboard

| Key                                      | Action                                                              |
| ---------------------------------------- | ------------------------------------------------------------------- |
| `Enter`, `Space`, `ArrowDown`, `ArrowUp` | Opens the popup from the trigger and highlights the selected item.  |
| `ArrowDown`, `ArrowUp`                   | Moves the highlight between items.                                  |
| `Home`, `End`                            | Highlights the first or last item.                                  |
| Printable characters                     | Highlights the next matching item; on a closed trigger, selects it. |
| `Enter`, `Space`                         | Selects the highlighted item and closes the popup.                  |
| `Escape`                                 | Closes the popup and returns focus to the trigger.                  |

## API reference

### Select

Groups all parts of a single- or multiple-value select dropdown. Doesn't render its own HTML element.

Inherits `children`, `inputRef`, `name`, `form`, `autoComplete`, `id`, `required`, `readOnly`, `disabled`, `multiple`, `highlightItemOnHover`, `defaultOpen`, `onOpenChange`, `onOpenChangeComplete`, `open`, `modal`, `actionsRef`, `items`, `itemToStringLabel`, `itemToStringValue`, `isItemEqualToValue`, `defaultValue`, `value`, `onValueChange` from [Base UI Select.Root](https://base-ui.com/react/components/select#root).

### SelectContent

A styled select popup bundled with a portal, positioner, and scrollable list. Renders a `<div>` element.

**Props**

| Prop          | Type                           | Default   | Description                                                                                             |
| ------------- | ------------------------------ | --------- | ------------------------------------------------------------------------------------------------------- |
| `align?`      | `'center' \| 'end' \| 'start'` | `'start'` | How to align the popup relative to the specified side.                                                  |
| `sideOffset?` | `number \| OffsetFunction`     | `4`       | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance. |
| `children`    | `React.ReactNode`              | —         | The items and groups, rendered inside a scrollable list.                                                |

Inherits `className`, `render`, `style`, `finalFocus`, `side`, `alignOffset` from [Base UI Select.Popup](https://base-ui.com/react/components/select#popup).

**Data attributes**

| Attribute             | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `data-open`           | Present when the select is open.                                      |
| `data-closed`         | Present when the select is closed.                                    |
| `data-starting-style` | Present when the select begins animating in.                          |
| `data-ending-style`   | Present when the select is animating out.                             |
| `data-side`           | Indicates which side the popup is positioned relative to the trigger. |
| `data-align`          | Indicates how the popup is aligned relative to specified side.        |

**CSS variables**

| Variable             | Type     | Description                                                                            |
| -------------------- | -------- | -------------------------------------------------------------------------------------- |
| `--available-width`  | `number` | The available width between the trigger and the edge of the viewport.                  |
| `--available-height` | `number` | The available height between the trigger and the edge of the viewport.                 |
| `--anchor-width`     | `number` | The anchor's width.                                                                    |
| `--anchor-height`    | `number` | The anchor's height.                                                                   |
| `--transform-origin` | `string` | The coordinates that this element is anchored to. Used for animations and transitions. |

### SelectGroup

Groups related select items with the corresponding label. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Select.Group](https://base-ui.com/react/components/select#group).

### SelectGroupLabel

An accessible label that is automatically associated with its parent group. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Select.GroupLabel](https://base-ui.com/react/components/select#grouplabel).

### SelectItem

An individual option in the select popup. Renders a `<div>` element.

**Props**

| Prop     | Type    | Default | Description                               |
| -------- | ------- | ------- | ----------------------------------------- |
| `value?` | `Value` | —       | A unique value that identifies this item. |

Inherits `className`, `render`, `style`, `nativeButton`, `children`, `disabled`, `label` from [Base UI Select.Item](https://base-ui.com/react/components/select#item).

**Data attributes**

| Attribute          | Description                                  |
| ------------------ | -------------------------------------------- |
| `data-selected`    | Present when the select item is selected.    |
| `data-highlighted` | Present when the select item is highlighted. |
| `data-disabled`    | Present when the select item is disabled.    |

### SelectItemIndicator

Indicates whether the select item is selected. Renders a `<span>` element.

Inherits `className`, `render`, `style`, `keepMounted` from [Base UI Select.ItemIndicator](https://base-ui.com/react/components/select#itemindicator).

**Data attributes**

| Attribute             | Description                                     |
| --------------------- | ----------------------------------------------- |
| `data-starting-style` | Present when the indicator begins animating in. |
| `data-ending-style`   | Present when the indicator is animating out.    |

### SelectItemText

A text label of the select item. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Select.ItemText](https://base-ui.com/react/components/select#itemtext).

### SelectLabel

An accessible label that is automatically associated with the select trigger. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Select.Label](https://base-ui.com/react/components/select#label).

**Data attributes**

| Attribute       | Description                                                      |
| --------------- | ---------------------------------------------------------------- |
| `data-disabled` | Present when the component should ignore user interaction.       |
| `data-touched`  | Present when the field has been touched.                         |
| `data-dirty`    | Present when the field value has changed from its initial value. |
| `data-filled`   | Present when the field has a value.                              |
| `data-focused`  | Present when the field is focused.                               |

### SelectList

A container for the select items. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Select.List](https://base-ui.com/react/components/select#list).

### SelectPopup

A container for the select list. Renders a `<div>` element.

Inherits `children`, `finalFocus`, `className`, `render`, `style` from [Base UI Select.Popup](https://base-ui.com/react/components/select#popup).

**Data attributes**

| Attribute             | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `data-open`           | Present when the select is open.                                      |
| `data-closed`         | Present when the select is closed.                                    |
| `data-starting-style` | Present when the select begins animating in.                          |
| `data-ending-style`   | Present when the select is animating out.                             |
| `data-side`           | Indicates which side the popup is positioned relative to the trigger. |
| `data-align`          | Indicates how the popup is aligned relative to specified side.        |

### SelectPortal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to `<body>`. Renders a `<div>` element.

Inherits `container`, `className`, `render`, `style` from [Base UI Select.Portal](https://base-ui.com/react/components/select#portal).

### SelectPositioner

Positions the select popup. Renders a `<div>` element.

**Props**

| Prop                    | Type                           | Default   | Description                                                                                                       |
| ----------------------- | ------------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `align?`                | `'center' \| 'end' \| 'start'` | `'start'` | How to align the popup relative to the specified side.                                                            |
| `sideOffset?`           | `number \| OffsetFunction`     | `4`       | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance.           |
| `alignItemWithTrigger?` | `boolean`                      | `false`   | Whether the positioner overlaps the trigger so the selected item's text is aligned with the trigger's value text. |

Inherits `className`, `render`, `style`, `anchor`, `positionMethod`, `side`, `alignOffset`, `collisionBoundary`, `collisionPadding`, `sticky`, `arrowPadding`, `disableAnchorTracking`, `collisionAvoidance` from [Base UI Select.Positioner](https://base-ui.com/react/components/select#positioner).

**Data attributes**

| Attribute            | Description                                                           |
| -------------------- | --------------------------------------------------------------------- |
| `data-open`          | Present when the select popup is open.                                |
| `data-closed`        | Present when the select popup is closed.                              |
| `data-anchor-hidden` | Present when the anchor is hidden.                                    |
| `data-side`          | Indicates which side the popup is positioned relative to the trigger. |
| `data-align`         | Indicates how the popup is aligned relative to specified side.        |

**CSS variables**

| Variable             | Type     | Description                                                                            |
| -------------------- | -------- | -------------------------------------------------------------------------------------- |
| `--available-width`  | `number` | The available width between the trigger and the edge of the viewport.                  |
| `--available-height` | `number` | The available height between the trigger and the edge of the viewport.                 |
| `--anchor-width`     | `number` | The anchor's width.                                                                    |
| `--anchor-height`    | `number` | The anchor's height.                                                                   |
| `--transform-origin` | `string` | The coordinates that this element is anchored to. Used for animations and transitions. |

### SelectSeparator

A visual separator between items or groups. Renders a `<div>` element.

Inherits `orientation`, `className`, `render`, `style` from [Base UI Select.Separator](https://base-ui.com/react/components/select#separator).

**Data attributes**

| Attribute          | Description                       |
| ------------------ | --------------------------------- |
| `data-orientation` | The orientation of the separator. |

### SelectTrigger

A button that opens the select popup. Renders a `<button>` element.

**Props**

| Prop    | Type                             | Default    | Description                                         |
| ------- | -------------------------------- | ---------- | --------------------------------------------------- |
| `size?` | `'large' \| 'medium' \| 'small'` | `'medium'` | The height, padding, and type scale of the trigger. |

Inherits `children`, `disabled`, `className`, `render`, `style`, `nativeButton` from [Base UI Select.Trigger](https://base-ui.com/react/components/select#trigger).

**Data attributes**

| Attribute          | Description                                                                        |
| ------------------ | ---------------------------------------------------------------------------------- |
| `data-popup-open`  | Present when the corresponding select is open.                                     |
| `data-pressed`     | Present when the trigger is pressed.                                               |
| `data-disabled`    | Present when the select is disabled.                                               |
| `data-readonly`    | Present when the select is readonly.                                               |
| `data-popup-side`  | Indicates which side the corresponding popup is positioned relative to its anchor. |
| `data-required`    | Present when the select is required.                                               |
| `data-valid`       | Present when the select is in a valid state (when wrapped in Field.Root).          |
| `data-invalid`     | Present when the select is in an invalid state (when wrapped in Field.Root).       |
| `data-touched`     | Present when the select has been touched (when wrapped in Field.Root).             |
| `data-dirty`       | Present when the select's value has changed (when wrapped in Field.Root).          |
| `data-filled`      | Present when the select has a value (when wrapped in Field.Root).                  |
| `data-focused`     | Present when the select trigger is focused (when wrapped in Field.Root).           |
| `data-placeholder` | Present when the select doesn't have a value.                                      |

### SelectValue

A text label of the currently selected item. Renders a `<span>` element.

**Props**

| Prop        | Type                                                                                    | Default | Description                                                                                                                                   |
| ----------- | --------------------------------------------------------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `children?` | `((value: SelectSelectedValue<Value, Multiple>) => React.ReactNode) \| React.ReactNode` | —       | The content to show, or a function that formats the selected value. In `multiple` mode the function receives the selected values as an array. |

Inherits `className`, `render`, `style`, `placeholder` from [Base UI Select.Value](https://base-ui.com/react/components/select#value).

**Data attributes**

| Attribute          | Description                                   |
| ------------------ | --------------------------------------------- |
| `data-placeholder` | Present when the select doesn't have a value. |
