Documentation
Form Controls
Select

Select

This component is built upon fantastic @floating-ui/react (opens in a new tab) library.

This is helper text
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.

PropDefaultDescription
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

getOptionLabeloption => option.label ?? option
(option: T) => string

Getter for option label.

getOptionDisabledoption => 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

Default type of option if custom was not provided.

PropDefaultDescription
labeloption.label ?? option
React.ReactNode

Label of option

disabled
boolean

Option disabled state, used by isOptionDisabled