# NativeSelect A styled HTML select that keeps browser and device behavior for option menus, validation, submission and reset. [Interactive guide](/docs/components/native-select) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use NativeSelect for plain options that benefit from the browser or device picker. ### How to compose it Use NativeSelectOption and NativeSelectOptGroup, a visible label and a form name. Use the callback for one or multiple values as appropriate. ### What to verify Check the OS picker, submitted values and default restoration after form reset. ## Usage ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge' ``` - Use the native picker on mobile or in simple forms. For rich option content or a custom trigger, use Select. For a searchable collection, use Combobox. - NativeSelectOption and NativeSelectOptGroup preserve native behavior. On the main entry set fullWidth={false} for intrinsic sizing. The chevron is decorative and disappears for a multiple or multi-row listbox. - Supply native option and optgroup children. Give the control a visible label and name it to include the selection in FormData. - Use defaultValue to let the browser manage selection and restore defaults on reset. Pass value and a callback for controlled selection. - Use onValueChange for one value, or multiple and onValuesChange for an array. Native onChange receives the select event. ```tsx CSV JSON ``` ## Runnable examples ### Choose status ```tsx import { createContext, useContext } from 'react' import * as DefaultParts from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } export default function Example() { return () } ``` ### Groups ```tsx import { createContext, useContext } from 'react' import * as DefaultParts from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) const departments = [ { label: 'Engineering', roles: [['frontend', 'Frontend'], ['backend', 'Backend'], ['devops', 'DevOps']] }, { label: 'Sales', roles: [['sales-rep', 'Sales Rep'], ['account-manager', 'Account Manager'], ['sales-director', 'Sales Director']] }, { label: 'Operations', roles: [['support', 'Customer Support'], ['product-manager', 'Product Manager'], ['ops-manager', 'Operations Manager']] }, ] function DepartmentSelect() { const { NativeSelect, NativeSelectOption, NativeSelectOptGroup } = useContext(SelectLibrary) return Select department {departments.map(({ label, roles }) => {roles.map(([value, name]) => {name})} )} } export default function Example() { return () } ``` ### Disabled ```tsx import { createContext, useContext } from 'react' import * as DefaultParts from 'wss3-forge' import { Field } from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) function DisabledSelect() { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) return Stable Beta } export default function Example() { return () } ``` ### Invalid ```tsx import { createContext, useContext, useState } from 'react' import * as DefaultParts from 'wss3-forge' import { Field } from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) function InvalidSelect() { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) const [format, setFormat] = useState('') return Choose a format CSV JSON } export default function Example() { return () } ``` ### Sizes ```tsx import { createContext, useContext } from 'react' import * as DefaultParts from 'wss3-forge' import { Field, HStack } from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) function Sizes() { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) return {(['default', 'sm'] as const).map(size => Daily Weekly Monthly )} } export default function Example() { return () } ``` ### RTL ```tsx import { createContext, useContext } from 'react' import * as DefaultParts from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } function RtlStatus() { return } export default function Example() { return () } ``` ### Grouped shipping options with native submit and reset ```tsx import { createContext, useContext, useState } from 'react' import * as DefaultParts from 'wss3-forge' import { Button, Field, FieldDescription, HStack, VStack } from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) function ShippingForm() { const { NativeSelect, NativeSelectOption, NativeSelectOptGroup } = useContext(SelectLibrary) const [value, setValue] = useState('') return (
setValue('')} onSubmit={event => { event.preventDefault() setValue(String(new FormData(event.currentTarget).get('shipping') ?? '')) }}> Standard delivery Express delivery Parcel locker Store pickup {value && Submitted shipping service: {value}}
) } export default function Example() { return () } ``` ### Controlled multiple selection ```tsx import { createContext, useContext, useState } from 'react' import * as DefaultParts from 'wss3-forge' import { Field, VStack } from 'wss3-forge' type SelectParts = Pick const SelectLibrary = createContext(DefaultParts) function NotificationChannels() { const { NativeSelect, NativeSelectOption } = useContext(SelectLibrary) const [channels, setChannels] = useState(['email', 'in-app']) return ( Email In-app SMS ) } export default function Example() { return () } ``` ## Primitive libraries ### Base UI Each entry renders an HTML select. Registry entries default to intrinsic width and size="default". Use fullWidth inside a form. className styles the wrapper and inputClassName styles the select. ```sh npm install wss3-forge @base-ui/react ``` ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } export default function Example() { return () } ``` #### Groups ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/base-ui' const departments = [ { label: 'Engineering', roles: [['frontend', 'Frontend'], ['backend', 'Backend'], ['devops', 'DevOps']] }, { label: 'Sales', roles: [['sales-rep', 'Sales Rep'], ['account-manager', 'Account Manager'], ['sales-director', 'Sales Director']] }, { label: 'Operations', roles: [['support', 'Customer Support'], ['product-manager', 'Product Manager'], ['ops-manager', 'Operations Manager']] }, ] function DepartmentSelect() { return Select department {departments.map(({ label, roles }) => {roles.map(([value, name]) => {name})} )} } export default function Example() { return () } ``` #### Disabled ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' import { Field } from 'wss3-forge' function DisabledSelect() { return Stable Beta } export default function Example() { return () } ``` #### Invalid ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' import { useState } from 'react' import { Field } from 'wss3-forge' function InvalidSelect() { const [format, setFormat] = useState('') return Choose a format CSV JSON } export default function Example() { return () } ``` #### Sizes ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' import { Field, HStack } from 'wss3-forge' function Sizes() { return {(['default', 'sm'] as const).map(size => Daily Weekly Monthly )} } export default function Example() { return () } ``` #### RTL ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } function RtlStatus() { return } export default function Example() { return () } ``` #### Grouped shipping options with native submit and reset ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/base-ui' import { useState } from 'react' import { Button, Field, FieldDescription, HStack, VStack } from 'wss3-forge' function ShippingForm() { const [value, setValue] = useState('') return (
setValue('')} onSubmit={event => { event.preventDefault() setValue(String(new FormData(event.currentTarget).get('shipping') ?? '')) }}> Standard delivery Express delivery Parcel locker Store pickup {value && Submitted shipping service: {value}}
) } export default function Example() { return () } ``` #### Controlled multiple selection ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/base-ui' import { useState } from 'react' import { Field, VStack } from 'wss3-forge' function NotificationChannels() { const [channels, setChannels] = useState(['email', 'in-app']) return ( Email In-app SMS ) } export default function Example() { return () } ``` ### Radix Each entry renders an HTML select. Registry entries default to intrinsic width and size="default". Use fullWidth inside a form. className styles the wrapper and inputClassName styles the select. ```sh npm install wss3-forge radix-ui ``` ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } export default function Example() { return () } ``` #### Groups ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/radix' const departments = [ { label: 'Engineering', roles: [['frontend', 'Frontend'], ['backend', 'Backend'], ['devops', 'DevOps']] }, { label: 'Sales', roles: [['sales-rep', 'Sales Rep'], ['account-manager', 'Account Manager'], ['sales-director', 'Sales Director']] }, { label: 'Operations', roles: [['support', 'Customer Support'], ['product-manager', 'Product Manager'], ['ops-manager', 'Operations Manager']] }, ] function DepartmentSelect() { return Select department {departments.map(({ label, roles }) => {roles.map(([value, name]) => {name})} )} } export default function Example() { return () } ``` #### Disabled ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' import { Field } from 'wss3-forge' function DisabledSelect() { return Stable Beta } export default function Example() { return () } ``` #### Invalid ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' import { useState } from 'react' import { Field } from 'wss3-forge' function InvalidSelect() { const [format, setFormat] = useState('') return Choose a format CSV JSON } export default function Example() { return () } ``` #### Sizes ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' import { Field, HStack } from 'wss3-forge' function Sizes() { return {(['default', 'sm'] as const).map(size => Daily Weekly Monthly )} } export default function Example() { return () } ``` #### RTL ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } function RtlStatus() { return } export default function Example() { return () } ``` #### Grouped shipping options with native submit and reset ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/radix' import { useState } from 'react' import { Button, Field, FieldDescription, HStack, VStack } from 'wss3-forge' function ShippingForm() { const [value, setValue] = useState('') return (
setValue('')} onSubmit={event => { event.preventDefault() setValue(String(new FormData(event.currentTarget).get('shipping') ?? '')) }}> Standard delivery Express delivery Parcel locker Store pickup {value && Submitted shipping service: {value}}
) } export default function Example() { return () } ``` #### Controlled multiple selection ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/radix' import { useState } from 'react' import { Field, VStack } from 'wss3-forge' function NotificationChannels() { const [channels, setChannels] = useState(['email', 'in-app']) return ( Email In-app SMS ) } export default function Example() { return () } ``` ### React Aria Each entry renders an HTML select. Registry entries default to intrinsic width and size="default". Use fullWidth inside a form. className styles the wrapper and inputClassName styles the select. ```sh npm install wss3-forge react-aria-components ``` ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } export default function Example() { return () } ``` #### Groups ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/react-aria' const departments = [ { label: 'Engineering', roles: [['frontend', 'Frontend'], ['backend', 'Backend'], ['devops', 'DevOps']] }, { label: 'Sales', roles: [['sales-rep', 'Sales Rep'], ['account-manager', 'Account Manager'], ['sales-director', 'Sales Director']] }, { label: 'Operations', roles: [['support', 'Customer Support'], ['product-manager', 'Product Manager'], ['ops-manager', 'Operations Manager']] }, ] function DepartmentSelect() { return Select department {departments.map(({ label, roles }) => {roles.map(([value, name]) => {name})} )} } export default function Example() { return () } ``` #### Disabled ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' import { Field } from 'wss3-forge' function DisabledSelect() { return Stable Beta } export default function Example() { return () } ``` #### Invalid ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' import { useState } from 'react' import { Field } from 'wss3-forge' function InvalidSelect() { const [format, setFormat] = useState('') return Choose a format CSV JSON } export default function Example() { return () } ``` #### Sizes ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' import { Field, HStack } from 'wss3-forge' function Sizes() { return {(['default', 'sm'] as const).map(size => Daily Weekly Monthly )} } export default function Example() { return () } ``` #### RTL ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' const statuses = [ ['todo', 'Todo', 'مهام'], ['in-progress', 'In Progress', 'قيد التنفيذ'], ['done', 'Done', 'منجز'], ['cancelled', 'Cancelled', 'ملغي'], ] function StatusSelect({ rtl = false }: { rtl?: boolean }) { return {rtl ? 'اختر الحالة' : 'Select status'} {statuses.map(([value, english, arabic]) => {rtl ? arabic : english})} } function RtlStatus() { return } export default function Example() { return () } ``` #### Grouped shipping options with native submit and reset ```tsx import { NativeSelect, NativeSelectOption, NativeSelectOptGroup } from 'wss3-forge/react-aria' import { useState } from 'react' import { Button, Field, FieldDescription, HStack, VStack } from 'wss3-forge' function ShippingForm() { const [value, setValue] = useState('') return (
setValue('')} onSubmit={event => { event.preventDefault() setValue(String(new FormData(event.currentTarget).get('shipping') ?? '')) }}> Standard delivery Express delivery Parcel locker Store pickup {value && Submitted shipping service: {value}}
) } export default function Example() { return () } ``` #### Controlled multiple selection ```tsx import { NativeSelect, NativeSelectOption } from 'wss3-forge/react-aria' import { useState } from 'react' import { Field, VStack } from 'wss3-forge' function NotificationChannels() { const [channels, setChannels] = useState(['email', 'in-app']) return ( Email In-app SMS ) } export default function Example() { return () } ``` ## Root package API ### NativeSelect A styled HTML select that keeps browser and device behavior for option menus, validation, submission and reset. Props type: `NativeSelectProps` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes, SelectHTMLAttributes **Composition exports** - `NativeSelectOption` (named export) - `NativeSelectOptGroup` (named export) - `size?` — `ControlSize | 'default'` Default `'md'`. Options `"default"`, `"sm"`, `"md"`, `"lg"`, `"xs"`, `"xl"`. Forge size and text scale for the control. - `fullWidth?` — `boolean` Default `true`. Set false for an intrinsic, content-sized selector. Defaults to true in the main Forge entry. - `containerClassName?` — `string` - `visibleRows?` — `number` Native HTML size, for listboxes and visible rows in multiple mode. - `onValueChange?` — `(value: string, event: ChangeEvent) => void` Receives the changed value in single-selection mode. - `onValuesChange?` — `(values: string[], event: ChangeEvent) => void` Receives selected values in multiple-selection mode. - `multiple?` — `boolean | undefined` Allow users to select more than one option. - `ref?` — `React.LegacyRef | undefined` ### NativeSelectOption Props type: `OptionHTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes, OptionHTMLAttributes - `ref?` — `React.LegacyRef | undefined` ### NativeSelectOptGroup Props type: `OptgroupHTMLAttributes` Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes, OptgroupHTMLAttributes - `ref?` — `React.LegacyRef | undefined` ## Related types ```ts export type ControlSize = keyof typeof SIZES export interface NativeSelectProps extends Omit, 'size'> { size?: ControlSize | 'default' /** Set false for an intrinsic, content-sized selector. Defaults to true in the main Forge entry. */ fullWidth?: boolean containerClassName?: string /** Native HTML size, for listboxes and visible rows in multiple mode. */ visibleRows?: number onValueChange?: (value: string, event: ChangeEvent) => void onValuesChange?: (values: string[], event: ChangeEvent) => void } ``` ## Optional primitive contracts - [wss3-forge/base-ui · NativeSelect contract](/ai/skill/primitive-api/NativeSelect.json) - [wss3-forge/radix · NativeSelect contract](/ai/skill/primitive-api/NativeSelect.json) - [wss3-forge/react-aria · NativeSelect contract](/ai/skill/primitive-api/NativeSelect.json)