--- title: NativeSelect description: "`NativeSelect` is a component used for allowing users to select one value from a list of options. It displays a native dropdown list provided by the browser (user agent)." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/native-select/native-select.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/native-select - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-nativeselect--basic --- ```tsx 日比野カフカ 市川レノ 亜白ミナ 四ノ宮キコル ``` ## Usage :::note `NativeSelect` is a native UI component provided by the browser (user agent). It utilizes the browser's default functionality to display a dropdown list. If you want to extend the functionality and use a more styled component, please check [Select](https://yamada-ui.com/components/forms/select.md). ::: ```tsx import { NativeSelect } from "@yamada-ui/react" ``` ```tsx import { NativeSelect } from "@/components/ui" ``` ```tsx import { NativeSelect } from "@workspaces/ui" ``` ```tsx ``` ### Use items ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ``` ### Change variant ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( {(variant) => ( )} ) ``` ### Change size ```tsx preview functional const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( {(size) => ( )} ) ``` ### Set default value To set a default value, set a value to `defaultValue`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( ) ``` ### Grouping To group options, use `NativeSelect.Group`. ```tsx 鳴海弦 長谷川エイジ 日比野カフカ 市川レノ 亜白ミナ 四ノ宮キコル ``` ```tsx const items = useMemo( () => [ { label: "怪獣8号", value: "怪獣8号" }, { label: "第1部隊", items: [ { label: "鳴海弦", value: "鳴海弦" }, { label: "長谷川エイジ", value: "長谷川エイジ" }, ], }, { label: "第3部隊", items: [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], }, ], [], ) return ``` ### Exclude placeholder from options By default, a placeholder is included in the options. To exclude the placeholder from options, set `includePlaceholder` to `false`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( ) ``` ### Disable option To disable an option, set `disabled` to `true` in `NativeSelect.Option`. ```tsx 日比野カフカ 市川レノ 亜白ミナ 四ノ宮キコル ``` ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { disabled: true, label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ``` ### Disable To disable, set `disabled` to `true`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( {(variant) => ( )} ) ``` ### Read-Only To make read-only, set `readOnly` to `true`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( {(variant) => ( )} ) ``` ### Invalid To make invalid, set `invalid` to `true`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( {(variant) => ( )} ) ``` ### Change border color To change the border color, set a color to `focusBorderColor` or `errorBorderColor`. ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( ) ``` ### Customize icon ```tsx const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( } /> ) ``` ### Control ```tsx const [value, setValue] = useState("日比野カフカ") const items = useMemo( () => [ { label: "日比野カフカ", value: "日比野カフカ" }, { label: "市川レノ", value: "市川レノ" }, { label: "亜白ミナ", value: "亜白ミナ" }, { label: "四ノ宮キコル", value: "四ノ宮キコル" }, ], [], ) return ( setValue(e.target.value)} /> ) ``` ## Props ### NativeSelect.Root | Prop | Default | Type | Description | | -------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `elementProps` | - | `InputGroup.ElementProps` | The props for the end element. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is focused. | | `icon` | - | `ReactNode` | The icon to be used in the select. | | `iconProps` | - | `NativeSelectIconProps` | Props for icon element. | | `includePlaceholder` | `true` | `boolean` | If `true`, include placeholder in options. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `items` | `[]` | `NativeSelectItem[]` | If provided, generate options based on items. | | `placeholder` | - | `string` | The placeholder for select. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `rootProps` | - | `InputGroup.RootProps` | Props for root element. | ## Accessibility Currently, this section is being updated due to the migration of v2.