Skip to content
FormsInteractive playground

Select

Selection with search, groups, asynchronous loading and option creation.

Preparing the playground…
Text and Markdown example
Select · Example
1<Select aria-label="Framework" placeholder="Choose your framework" options={[{value:"next",label:"Next.js"},{value:"react",label:"React"},{value:"native",label:"React Native"}]} />
Read documentation in Markdown

How to use it

The API uses options with label/value objects; onChange receives the selected object. loadOptions enables asynchronous loading; isCreatable allows new options and can be combined with loadOptions. Use defaultOptions for initial loading and cacheOptions to reuse searches. Do not compose SelectItem as a Radix Select: compatibility exports are HTML elements.

Import

React / Next.js
1import { Select, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectLabel, SelectItem, SelectSeparator, SelectScrollDownButton, SelectScrollUpButton } from "@kivora/nextjs";

Interactive examples run inside a component with "use client". The playground's Copy button includes the imports needed for the current example.

API reference 0.2.0

Types from the installed published version, including component properties and common HTML attributes. “Optional” does not imply a default value; omitting a property lets the component decide.

PropertyTypeDescription
allowCreateWhileLoadingbooleanAllow options to be created while the `isLoading` prop is true. Useful to prevent the "create new ..." option being displayed while async results are still being loaded.
aria-errormessagestringHTML ID of an element containing an error message related to the input*
aria-invalidboolean | "true" | "false" | "grammar" | "spelling"Indicate if the value entered in the field is invalid *
aria-labelstringAccessible name of the control.
aria-labelledbystringHTML ID of an element that should be used as the label (for assistive tech)
aria-live"off" | "assertive" | "polite"Used to set the priority with which screen reader should treat updates to live regions. The possible settings are: off, polite (default) or assertive
ariaLiveMessagesAriaLiveMessages<Option, IsMulti, Group>Customise the messages used by the aria-live component
autoFocusbooleanFocus the control when it is mounted
backspaceRemovesValuebooleanRemove the currently focused option when the user presses backspace when Select isClearable or isMulti
blurInputOnSelectbooleanRemove focus from the input when the user selects an option (handy for dismissing the keyboard on touch devices)
cacheOptionsanyKeep loaded options for reuse.
captureMenuScrollbooleanWhen the user reaches the top/bottom of the menu, prevent scroll on the scroll-parent
classNamestringAdditional CSS classes to customize the element.
classNamePrefixstring | nullIf provided, all inner components will be given a prefixed className attribute. This is useful when styling via CSS classes instead of the Styles API approach.
classNamesClassNamesConfig<Option, IsMulti, Group>Provide classNames based on state for each inner component
closeMenuOnScrollboolean | ((event: Event) => boolean)If `true`, close the select menu when the user scrolls the document/body. If a function, takes a standard javascript `ScrollEvent` you return a boolean: `true` => The menu closes `false` => The menu stays open This is useful when you have a scrollable modal and want to portal the menu out, but want to avoid graphical issues.
closeMenuOnSelectbooleanClose the select menu when the user selects an option
componentsPartial<SelectComponents<Option, IsMulti, Group>>This complex object includes all the compositional components that are used in `react-select`. If you wish to overwrite a component, pass in an object with the appropriate namespace. If you only wish to restyle a component, we recommend using the `styles` prop instead. For a list of the components that can be passed in, and the shape that will be passed to them, see [the components docs](/components)
controlShouldRenderValuebooleanWhether the value of the select, e.g. SingleValue, should be displayed in the control.
createOptionPosition"first" | "last"Sets the position of the createOption element in your options list. Defaults to 'last'
defaultInputValuestringConfigures defaultInputValue. The type describes the supported values and structure.
defaultMenuIsOpenbooleanConfigures defaultMenuIsOpen. The type describes the supported values and structure.
defaultOptionsboolean | OptionsOrGroups<Option, Group>The default set of options to show before the user starts searching. When set to `true`, the results for loadOptions('') will be autoloaded.
defaultValuePropsValue<Option>Initial value when the component manages its own state.
delimiterstringDelimiter used to join multiple values into a single HTML Input value
escapeClearsValuebooleanClear all values when the user presses escape AND the menu is closed
filterOption((option: FilterOptionOption<Option>, inputValue: string) => boolean) | nullCustom method to filter whether an option should be displayed in the menu
formstringSets the form attribute on the input
formatCreateLabel((inputValue: string) => ReactNode)Gets the label for the "create new ..." option in the menu. Is given the current input value.
formatGroupLabel((group: Group) => ReactNode)Formats group labels in the menu as React components An example can be found in the [Replacing builtins](/advanced#replacing-builtins) documentation.
formatOptionLabel((data: Option, formatOptionLabelMeta: FormatOptionLabelMeta<Option>) => ReactNode)Formats option labels in the menu and control as React components
getNewOptionData((inputValue: string, optionLabel: ReactNode) => Option)Returns the data for the new option when it is created. Used to display the value, and is passed to `onChange`.
getOptionLabelGetOptionLabel<Option>Resolves option data to a string to be displayed as the label by components Note: Failure to resolve to a string type can interfere with filtering and screen reader support.
getOptionValueGetOptionValue<Option>Resolves option data to a string to compare options and specify value attributes
hideSelectedOptionsbooleanHide the selected option from the menu
idstringElement identifier; associates labels and descriptions.
inputIdstringThe id of the search input
inputValuestringThe value of the search input
instanceIdstring | numberDefine an id prefix for the select components e.g. {your-id}-value
isClearablebooleanIs the select value clearable
isCreatablebooleanAllow creating options. Can be combined with loadOptions.
isDisabledbooleanIs the select disabled
isLoadingbooleanIs the select in a state of loading (async) Will cause the select to be displayed in the loading state, even if the Async select is not currently waiting for loadOptions to resolve
isMultiIsMultiAllow multiple option selection.
isOptionDisabled((option: Option, selectValue: Options<Option>) => boolean)Override the built-in logic to detect whether an option is disabled An example can be found in the [Replacing builtins](/advanced#replacing-builtins) documentation.
isOptionSelected((option: Option, selectValue: Options<Option>) => boolean)Override the built-in logic to detect whether an option is selected
isRtlbooleanIs the select direction right-to-left
isSearchablebooleanWhether to enable search functionality
isValidNewOption((inputValue: string, value: Options<Option>, options: OptionsOrGroups<Option, Group>, accessors: Accessors<Option>) => boolean)Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array.
loadingMessage((obj: { inputValue: string; }) => ReactNode)Async: Text to display when loading options
loadOptions((inputValue: string, callback: (options: OptionsOrGroups<Option, Group>) => void) => void | Promise<OptionsOrGroups<Option, Group>>)Load or filter options and return a promise or use the supported callback.
maxMenuHeightnumberMaximum height of the menu before scrolling
menuClassNamestringCSS classes for the specified element.
menuIsOpenbooleanWhether the menu is open
menuPlacement"auto" | "top" | "bottom"Default placement of the menu in relation to the control. 'auto' will flip when there isn't enough space below the control.
menuPortalTargetHTMLElement | nullWhether the menu should use a portal, and where it should attach An example can be found in the [Portaling](/advanced#portaling) documentation
menuPosition"absolute" | "fixed"The CSS position value of the menu, when "fixed" extra layout management is required
menuShouldBlockScrollbooleanWhether to block scroll events when the menu is open
menuShouldScrollIntoViewbooleanWhether the menu should be scrolled into view when it opens
minMenuHeightnumberMinimum height of the menu before flipping
mobileSheetOptionsOptionsOrGroups<Option, Group>Configures mobileSheetOptions. The type describes the supported values and structure.
mobileSheetTitlestringConfigures mobileSheetTitle. The type describes the supported values and structure.
namestringName used to identify the control in forms.
noOptionsMessage((obj: { inputValue: string; }) => ReactNode)Text to display when there are no options
onBlurFocusEventHandler<HTMLInputElement>Handle blur events on the control
onChange((newValue: OnChangeValue<Option, IsMulti>, actionMeta: ActionMeta<Option>) => void)Change event. Check the type: some controls return an object, others a DOM event.
onCreateOption((inputValue: string) => void)If provided, this will be called with the input value when a new option is created, and `onChange` will **not** be called. Use this when you need more control over what happens when new options are created.
onFocusFocusEventHandler<HTMLInputElement>Handle focus events on the control
onInputChange((newValue: string, actionMeta: InputActionMeta) => void)Handle change events on the input
onKeyDownKeyboardEventHandler<HTMLDivElement>Handle key down events on the select
onMenuClose(() => void)Handle the menu closing
onMenuOpen(() => void)Handle the menu opening
onMenuScrollToBottom((event: WheelEvent | TouchEvent) => void)Fired when the user scrolls to the bottom of the menu
onMenuScrollToTop((event: WheelEvent | TouchEvent) => void)Fired when the user scrolls to the top of the menu
openMenuOnClickbooleanAllows control of whether the menu is opened when the Select is clicked
openMenuOnFocusbooleanAllows control of whether the menu is opened when the Select is focused
optionClassNamestringCSS classes for the specified element.
optionsOptionsOrGroups<Option, Group>Component options or configuration. See the type structure.
pageSizenumberNumber of rows per page.
placeholderReactNodeShort hint displayed when there is no value.
requiredbooleanIndicates that a value is required.
screenReaderStatus((obj: { count: number; }) => string)Status to relay to screen readers
stylesStylesConfig<Option, IsMulti, Group>Style modifier methods A basic example can be found at the bottom of the [Replacing builtins](/advanced#replacing-builtins) documentation.
tabIndexnumberKeyboard focus order and availability.
tabSelectsValuebooleanSelect the currently focused option when the user presses tab
themeThemeConfigComponent theme or theme identifier, depending on the API.
triggerClassNamestringCSS classes for the specified element.
valuePropsValue<Option>Controlled value. Update it from the change callback.

Subcomponents and composition

Review each component's properties and published declaration. Native and accessibility attributes are inherited from the element specified by its type.

Select88 properties
Select · TypeScript
1Select: SelectCallable
SelectTrigger0 properties

HTML compatibility export. See the root component's usage guide.

SelectValue0 properties

HTML compatibility export. See the root component's usage guide.

SelectContent0 properties

HTML compatibility export. See the root component's usage guide.

SelectGroup0 properties

HTML compatibility export. See the root component's usage guide.

SelectLabel0 properties

HTML compatibility export. See the root component's usage guide.

SelectItem0 properties

HTML compatibility export. See the root component's usage guide.

SelectSeparator0 properties

HTML compatibility export. See the root component's usage guide.

SelectScrollDownButton1 properties
PropertyTypeDescription
childrenReactNodeContent or child elements of the component.
SelectScrollDownButton · TypeScript
1SelectScrollDownButton: React.ExoticComponent<React.FragmentProps>
SelectScrollUpButton1 properties
PropertyTypeDescription
childrenReactNodeContent or child elements of the component.
SelectScrollUpButton · TypeScript
1SelectScrollUpButton: React.ExoticComponent<React.FragmentProps>
API generated from @kivora/nextjs 0.2.0View package