Select
This component is built upon fantastic @floating-ui/react (opens in a new tab) library.
Placeholder
Overrides helper text
Code example
import { DropdownProps, Select } from '@creation-ui/react'
import { useState } from 'react'
const options = [
{ id: '1', label: 'Wade Cooper' },
{ id: '2', label: 'Arlene Mccoy' },
{ id: '3', label: 'Devon Webb' },
{ id: '4', label: 'Option disabled', disabled: true },
{ id: '5', label: 'Tom Cook' },
{ id: '6', label: 'Tanya Fox' },
{ id: '7', label: 'Hellen Schmidt' },
{ id: '8', label: 'Another option' },
]
export const SelectExample = ({ ...props }: DropdownProps) => {
const [value, setValue] = useState(null)
const onClear = () => setValue(null)
return (
<Select
label={'Person'}
value={value}
placeholder='Select value'
clearable
onChange={setValue}
onClear={onClear}
options={options}
/>
)
}
Component API
Select component props. Extends props of InputBase component.
Prop | Default | Description |
options | [] | T[] List available options |
renderOption | — | ((option: RenderOptionProps, index:number) => React.ReactNode) Function to render option |
value | — | T Current value of component |
onChange | — | (value: T | T[]) => void Change event callback |
getOptionLabel | option => option.label ?? option | (option: T) => string Getter for option label. |
getOptionDisabled | option => option.disabled | (option: T) => boolean Getter for option disabled state. |
isOptionEqualToValue | _isOptionEqualToValue | (option: T, value?: T | null) => boolean Function to compare option and value. |
renderOption | _renderOption | (props: RenderOptionProps, option: T) => ReactNode Function rendering option in dropdown. Docs |
renderSelection | _renderSelection | (option: T) => ReactNode Function rendering single selection. Docs |
Prop | Default | Description |
label | option.label ?? option | React.ReactNode Label of option |
disabled | — | boolean Option disabled state, used by |