NativeSelect

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

Usage

import { NativeSelect } from "@yamada-ui/react"
<NativeSelect.Root>
  <NativeSelect.Group>
    <NativeSelect.Option />
  </NativeSelect.Group>
  <NativeSelect.Option />
</NativeSelect.Root>

Use items

Change variant

Change size

Set default value

To set a default value, set a value to defaultValue.

Grouping

To group options, use NativeSelect.Group.

Exclude placeholder from options

By default, a placeholder is included in the options. To exclude the placeholder from options, set includePlaceholder to false.

Disable option

To disable an option, set disabled to true in NativeSelect.Option.

Disable

To disable, set disabled to true.

Read-Only

To make read-only, set readOnly to true.

Invalid

To make invalid, set invalid to true.

Change border color

To change the border color, set a color to focusBorderColor or errorBorderColor.

Customize icon

Control

Props

Accessibility

If you are not using Field.Root, set aria-label or aria-labelledby to NativeSelect.Root.

const items = useMemo<NativeSelect.Item[]>(
  () => [
    { label: "日比野カフカ", value: "日比野カフカ" },
    { label: "市川レノ", value: "市川レノ" },
    { label: "亜白ミナ", value: "亜白ミナ" },
    { label: "四ノ宮キコル", value: "四ノ宮キコル" },
  ],
  [],
)

return (
  <NativeSelect.Root
    items={items}
    placeholder="Select a character"
    aria-label="キャラクター"
  />
)
const items = useMemo<NativeSelect.Item[]>(
  () => [
    { label: "日比野カフカ", value: "日比野カフカ" },
    { label: "市川レノ", value: "市川レノ" },
    { label: "亜白ミナ", value: "亜白ミナ" },
    { label: "四ノ宮キコル", value: "四ノ宮キコル" },
  ],
  [],
)

return (
  <VStack gap="sm">
    <Heading as="h3" id="label">
      キャラクター
    </Heading>

    <NativeSelect.Root
      items={items}
      placeholder="Select a character"
      aria-labelledby="label"
    />
  </VStack>
)

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
NativeSelect.Fieldaria-describedbyIf NativeSelect.Field is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
aria-disabledSets to "true" when disabled or readOnly is set.
aria-invalidSets to "true" when invalid is set.
aria-labelIf aria-label is not set, the placeholder value is set.
aria-requiredSets to "true" if required is set.