Web · Components
Select
Select box.
10 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
SelectField: etiket, zorunlu alan ve form
Import
Select box. Options are given with items; clicking opens a list drawn with the theme's colors.
- Options: plain text, a
{ value, label, icon, description, disabled, tooltip }object or a{ group, items }group. Group headings are separated by a divider line and spacing. - Search:
search="auto"(default) opens the search box with more than 20 options. Locale-specific characters and accents are ignored, matches are highlighted. - Large lists: The list is virtualized; even with 10,000 options only the visible rows are drawn, the next ones are added while scrolling.
- Loading:
itemscan be a Promise or function ("Loading" shows while loading, a "Try again" button appears on error). WithloadItems, search runs on the server and the list loads page by page while scrolling. - Multiple selection:
multipleselects several values; the list doesn't close on selection. - Keyboard: ↑/↓ or letter keys work on the closed box too; while open ↑/↓, PageUp/PageDown, Home/End navigate, Enter selects, Esc closes.
- Mobile: Instead of the operating system's picker, a theme-matching panel opens from the bottom; rows are tall enough to tap comfortably with a thumb, and it closes by pulling down and with the back button. The search box doesn't open the keyboard by itself; it opens on tap and the panel moves above the keyboard.
- Form: Thanks to a hidden native
<select>it joinsFormDatawithname,requiredworks with browser validation and it returns to the initial value on form reset. Clicking<Label htmlFor>opens the list.
To use it with a label, description and error message see SelectField.
Examples
SelectItem
interfaceAn option inside Select.
| Name | Type | Description |
|---|---|---|
value | string | Value submitted to the form and used with value/onValueChange. |
label? | ReactNode | Visible text. If omitted, value is shown. |
icon? | IconProp | Icon before the text: name ("user") or element. |
description? | ReactNode | Small description below the text (single line; truncated if it doesn't fit). |
disabled? | boolean | Can't be selected. |
keywords? | readonly string[] | Extra words to match in search (e.g. a plate code, an old name). Search already looks at the label text and the value. |
tooltip? | TooltipProp | Tooltip shown when hovering the item. Good for explaining why a disabled item can't be selected. See TooltipProp. |
SelectGroup
interfaceOption group with a heading.
| Name | Type | Description |
|---|---|---|
group | ReactNode | Heading of the group. |
items | readonly (string | SelectItem)[] | Options in the group. |
SelectEntry
typeAn element of the Select items array: plain text (value and label are the same), a { value, label, icon… } object or a { group, items } group.
SelectPage
interfaceOne page of response from the Select loadItems function.
| Name | Type | Description |
|---|---|---|
items | readonly SelectEntry[] | Items on this page. |
hasMore? | boolean | Whether there are more pages. If true, the next page is requested when the list scrolls to the end. |
SelectLoadContext
interfaceInfo given to the Select loadItems function.
| Name | Type | Description |
|---|---|---|
query | string | Text in the search box (can be empty). |
page | number | Requested page; the first page is 0. Starts from 0 when the search changes. |
signal | AbortSignal | Cancels the old request when the search changes or the list closes; pass it with fetch(url, { signal }). |
SelectClassNames
interfaceClasses that can be passed to the inner parts of Select.
| Name | Type | Description |
|---|---|---|
trigger? | string | Open button (the visible box of the field). |
content? | string | Opened panel (e.g. w-80 for width). |
search? | string | Search box. |
item? | string | Each option. |
SingleSelectProps
interfaceSingle-select Select.
| Name | Type | Default | Description |
|---|---|---|---|
multiple? | false | false | If true, several options can be selected. |
value? | string | Selected value in controlled use; "" for none. | |
defaultValue? | string | Initial value in uncontrolled use. | |
onValueChange? | (value: string, item: SelectItem | undefined) => void | Called with the new value and the selected item when the selection changes ("" when cleared). | |
renderValue? | (item: SelectItem) => ReactNode | How the selected item looks in the box; the list keeps label. E.g. in a country code picker the list shows "Türkiye" and the box only "+90". | |
variant? | FieldVariant | CustomVariant<"field"> | Look: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, otherwise outline. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
items? | SelectItemsSource | Options. Can be given in three forms: - Array: plain text ("London"), a { value, label, icon, description, disabled } object or a { group, items } group. See SelectEntry. - Promise: e.g. a request started in a server component. "Loading" is shown until it arrives. - Function: () => fetch(...). Called once on first open (or right away if there is a selected value); change key to reload. Search runs over these items in the browser. For server search and pagination use loadItems (SelectProps.loadItems). | |
loadItems? | SelectLoader | Function that searches the server for options and fetches them page by page. When the list opens the first page is requested, while typing (with a 250 ms debounce) the first page of that search, and as the list scrolls to the end the next page. Old requests are cancelled with signal. Returns an array or { items, hasMore }. To show the label of the selected value, the first page is requested even before opening if a value is given; selected items are remembered. | |
search? | boolean | "auto" | "auto" | Search box above the list. - "auto": visible with more than 20 options, hidden with fewer. Always visible with loadItems (search runs on the server). - true / false: always visible / never visible. Search ignores case, locale-specific characters and accents ("cankaya" → "Çankaya") and highlights the matching part. |
searchPlaceholder? | string | "Ara…"` (`messages.search`) | Placeholder of the search box. |
placeholder? | ReactNode | "Seçiniz"` (`messages.select`) | Text or content shown while nothing is selected (e.g. an item with an icon). |
emptyMessage? | ReactNode | Content shown when the list is empty or the search finds nothing. | |
icon? | IconProp | Icon at the start of the box (if the selected item has its own icon, that is shown). | |
clearable? | boolean | false | Whether to show a × button that clears the selection. For optional fields, so the user can undo their selection. |
name? | string | Form field name; the selected value(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to (if outside the form). | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button; <Label htmlFor> links to it. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the list is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | Called when the list opens or closes. | |
tooltip? | TooltipProp | Tooltip shown when hovering the box. In labeled fields (SelectField) the tooltip is shown on the ⓘ icon next to the label. See TooltipProp. | |
className? | string | Classes added to the container (e.g. w-56 for width). | |
classNames? | SelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name if there is no visible label. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. SelectField passes it itself. | |
aria-invalid? | boolean | "true" | "false" | Show the field as invalid (red border). SelectField passes it itself. |
MultiSelectProps
interfaceMulti-select Select.
| Name | Type | Default | Description |
|---|---|---|---|
multiple | true | Several options can be selected; the list doesn't close on selection. | |
value? | readonly string[] | Selected values in controlled use. | |
defaultValue? | readonly string[] | Initial values in uncontrolled use. | |
onValueChange? | (value: string[], items: SelectItem[]) => void | Called with the new values and their items when the selection changes. | |
variant? | FieldVariant | CustomVariant<"field"> | Look: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, otherwise outline. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
items? | SelectItemsSource | Options. Can be given in three forms: - Array: plain text ("London"), a { value, label, icon, description, disabled } object or a { group, items } group. See SelectEntry. - Promise: e.g. a request started in a server component. "Loading" is shown until it arrives. - Function: () => fetch(...). Called once on first open (or right away if there is a selected value); change key to reload. Search runs over these items in the browser. For server search and pagination use loadItems (SelectProps.loadItems). | |
loadItems? | SelectLoader | Function that searches the server for options and fetches them page by page. When the list opens the first page is requested, while typing (with a 250 ms debounce) the first page of that search, and as the list scrolls to the end the next page. Old requests are cancelled with signal. Returns an array or { items, hasMore }. To show the label of the selected value, the first page is requested even before opening if a value is given; selected items are remembered. | |
search? | boolean | "auto" | "auto" | Search box above the list. - "auto": visible with more than 20 options, hidden with fewer. Always visible with loadItems (search runs on the server). - true / false: always visible / never visible. Search ignores case, locale-specific characters and accents ("cankaya" → "Çankaya") and highlights the matching part. |
searchPlaceholder? | string | "Ara…"` (`messages.search`) | Placeholder of the search box. |
placeholder? | ReactNode | "Seçiniz"` (`messages.select`) | Text or content shown while nothing is selected (e.g. an item with an icon). |
emptyMessage? | ReactNode | Content shown when the list is empty or the search finds nothing. | |
icon? | IconProp | Icon at the start of the box (if the selected item has its own icon, that is shown). | |
clearable? | boolean | false | Whether to show a × button that clears the selection. For optional fields, so the user can undo their selection. |
name? | string | Form field name; the selected value(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to (if outside the form). | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button; <Label htmlFor> links to it. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the list is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | Called when the list opens or closes. | |
tooltip? | TooltipProp | Tooltip shown when hovering the box. In labeled fields (SelectField) the tooltip is shown on the ⓘ icon next to the label. See TooltipProp. | |
className? | string | Classes added to the container (e.g. w-56 for width). | |
classNames? | SelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name if there is no visible label. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. SelectField passes it itself. | |
aria-invalid? | boolean | "true" | "false" | Show the field as invalid (red border). SelectField passes it itself. |
SelectProps
typeProps of the Select component.
| Name | Type | Default | Description |
|---|---|---|---|
multiple? | false | true | false | If true, several options can be selected. |
value? | string | readonly string[] | Selected value in controlled use; "" for none. | |
defaultValue? | string | readonly string[] | Initial value in uncontrolled use. | |
onValueChange? | (value: string, item: SelectItem | undefined) => void | (value: string[], items: SelectItem[]) => void | Called with the new value and the selected item when the selection changes ("" when cleared). | |
renderValue? | (item: SelectItem) => ReactNode | How the selected item looks in the box; the list keeps label. E.g. in a country code picker the list shows "Türkiye" and the box only "+90".(SingleSelectProps) | |
variant? | FieldVariant | CustomVariant<"field"> | Look: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, otherwise outline. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
items? | SelectItemsSource | Options. Can be given in three forms: - Array: plain text ("London"), a { value, label, icon, description, disabled } object or a { group, items } group. See SelectEntry. - Promise: e.g. a request started in a server component. "Loading" is shown until it arrives. - Function: () => fetch(...). Called once on first open (or right away if there is a selected value); change key to reload. Search runs over these items in the browser. For server search and pagination use loadItems (SelectProps.loadItems). | |
loadItems? | SelectLoader | Function that searches the server for options and fetches them page by page. When the list opens the first page is requested, while typing (with a 250 ms debounce) the first page of that search, and as the list scrolls to the end the next page. Old requests are cancelled with signal. Returns an array or { items, hasMore }. To show the label of the selected value, the first page is requested even before opening if a value is given; selected items are remembered. | |
search? | boolean | "auto" | "auto" | Search box above the list. - "auto": visible with more than 20 options, hidden with fewer. Always visible with loadItems (search runs on the server). - true / false: always visible / never visible. Search ignores case, locale-specific characters and accents ("cankaya" → "Çankaya") and highlights the matching part. |
searchPlaceholder? | string | "Ara…"` (`messages.search`) | Placeholder of the search box. |
placeholder? | ReactNode | "Seçiniz"` (`messages.select`) | Text or content shown while nothing is selected (e.g. an item with an icon). |
emptyMessage? | ReactNode | Content shown when the list is empty or the search finds nothing. | |
icon? | IconProp | Icon at the start of the box (if the selected item has its own icon, that is shown). | |
clearable? | boolean | false | Whether to show a × button that clears the selection. For optional fields, so the user can undo their selection. |
name? | string | Form field name; the selected value(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to (if outside the form). | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button; <Label htmlFor> links to it. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the list is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | Called when the list opens or closes. | |
tooltip? | TooltipProp | Tooltip shown when hovering the box. In labeled fields (SelectField) the tooltip is shown on the ⓘ icon next to the label. See TooltipProp. | |
className? | string | Classes added to the container (e.g. w-56 for width). | |
classNames? | SelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name if there is no visible label. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. SelectField passes it itself. | |
aria-invalid? | boolean | "true" | "false" | Show the field as invalid (red border). SelectField passes it itself. |