Skip to Content

Select

Select component allows capturing user input from a predefined list of options. This is a custom wrapper around Mantine’s Select with additional creatable functionality.

Import

import { Select } from '@tidbcloud/uikit'

Basic Usage

import { Select } from '@tidbcloud/uikit' function Demo() { return <Select label="Your favorite library" placeholder="Pick value" data={['React', 'Angular', 'Vue', 'Svelte']} /> }

Controlled

import { useState } from 'react' import { Select } from '@tidbcloud/uikit' function Demo() { const [value, setValue] = useState<string | null>(null) return <Select data={['React', 'Angular', 'Vue', 'Svelte']} value={value} onChange={setValue} /> }

Searchable

import { Select } from '@tidbcloud/uikit' function Demo() { return ( <Select label="Your favorite library" placeholder="Pick value" data={['React', 'Angular', 'Vue', 'Svelte']} searchable /> ) }

Clearable

import { Select } from '@tidbcloud/uikit' function Demo() { return ( <Select label="Your favorite library" placeholder="Pick value" data={['React', 'Angular', 'Vue', 'Svelte']} defaultValue="React" clearable /> ) }

Creatable (Custom Feature)

The @tidbcloud/uikit Select includes a creatable prop that allows users to create new options:

import { useState } from 'react' import { Select } from '@tidbcloud/uikit' function Demo() { const [data, setData] = useState(['React', 'Angular', 'Vue', 'Svelte']) return ( <Select label="Your favorite library" placeholder="Pick or create value" data={data} searchable creatable getCreateLabel={(query) => `+ Create ${query}`} onCreate={(query) => { const item = { value: query, label: query } setData((current) => [...current, query]) return item }} /> ) }

Grouped Options

import { Select } from '@tidbcloud/uikit' function Demo() { return ( <Select label="Your favorite library" placeholder="Pick value" data={[ { group: 'Frontend', items: ['React', 'Angular'] }, { group: 'Backend', items: ['Express', 'Django'] } ]} /> ) }

Nothing Found Message

import { Select } from '@tidbcloud/uikit' function Demo() { return ( <Select label="Your favorite library" placeholder="Pick value" data={['React', 'Angular', 'Vue', 'Svelte']} searchable nothingFoundMessage="Nothing found..." /> ) }

Disabled Options

import { Select } from '@tidbcloud/uikit' function Demo() { return ( <Select label="Your favorite library" placeholder="Pick value" data={[ { value: 'react', label: 'React' }, { value: 'ng', label: 'Angular' }, { value: 'vue', label: 'Vue', disabled: true }, { value: 'svelte', label: 'Svelte', disabled: true } ]} /> ) }

With Sections

import { Select } from '@tidbcloud/uikit' import { IconComponents } from '@tabler/icons-react' function Demo() { return ( <Select data={['React', 'Angular', 'Vue']} leftSection={<IconComponents size={16} />} leftSectionPointerEvents="none" label="Your favorite library" placeholder="Pick value" /> ) }

Key Props

PropTypeDefaultDescription
dataComboboxData-Data for options
valuestring | null-Controlled component value
defaultValuestring | null-Uncontrolled component default value
onChange(value: string | null, option: ComboboxItem) => void-Called when value changes
searchablebooleanfalseEnable search filtering
searchValuestring-Controlled search value
onSearchChange(value: string) => void-Called when search value changes
clearablebooleanfalseShow clear button when value is set
onClear() => void-Called when clear button is clicked
nothingFoundMessageReactNode-Message when no options match search
allowDeselectbooleantrueAllow deselecting by clicking selected option
withCheckIconbooleantrueShow check icon near selected option
checkIconPosition'left' | 'right''left'Position of check icon relative to option label
maxDropdownHeightnumber250Max height of dropdown
disabledbooleanfalseDisable the input
readOnlybooleanfalseMake the input read-only
errorReactNode-Error message

Creatable Props (Custom)

PropTypeDescription
creatablebooleanEnable creating new options
getCreateLabel(query: string) => stringFunction to generate create option label
onCreate(query: string) => ComboboxItem | null | undefinedCalled when new option is created

MultiSelect

MultiSelect component with creatable support. This is a custom wrapper in @tidbcloud/uikit that adds the same creatable functionality as Select.

Import

import { MultiSelect } from '@tidbcloud/uikit'

Basic Usage

import { MultiSelect } from '@tidbcloud/uikit' function Demo() { return ( <MultiSelect label="Your favorite libraries" placeholder="Pick values" data={['React', 'Angular', 'Vue', 'Svelte']} /> ) }

Creatable MultiSelect

import { useState } from 'react' import { MultiSelect } from '@tidbcloud/uikit' function Demo() { const [data, setData] = useState(['React', 'Angular', 'Vue']) return ( <MultiSelect label="Creatable MultiSelect" data={data} placeholder="Select or create items" searchable creatable getCreateLabel={(query) => `+ Create ${query}`} onCreate={(query) => { const item = { value: query, label: query } setData((current) => [...current, query]) return item }} /> ) }

MultiSelect Props

PropTypeDefaultDescription
dataComboboxData-Data for options
valuestring[]-Controlled component value
defaultValuestring[]-Uncontrolled component default value
onChange(value: string[]) => void-Called when value changes
searchablebooleanfalseEnable search filtering
clearablebooleanfalseShow clear button when value is set
nothingFoundMessageReactNode-Message when no options match search
maxValuesnumber-Maximum number of values
hidePickedOptionsbooleanfalseHide already picked options from dropdown
maxDropdownHeightnumber250Max height of dropdown
disabledbooleanfalseDisable the input
errorReactNode-Error message

MultiSelect Creatable Props (Custom)

PropTypeDescription
creatablebooleanEnable creating new options
getCreateLabel(query: string) => stringFunction to generate create option label
onCreate(query: string) => ComboboxItem | null | undefinedCalled when new option is created
Last updated on