Skip to content

Select

Single selection dropdown with search and portal support.

Also known as: dropdown, picker, option selector, single select

View in Storybook

When to use

  • Choosing one option from a predefined list. For multiple selections, use MultiSelect.
  • For search with suggestions, use Autocomplete.

Import

tsx
import { Select } from '@vacano/ui'

Usage

tsx
const [value, setValue] = useState('')

const options = [
  { value: 'us', label: 'United States' },
  { value: 'uk', label: 'United Kingdom' },
  { value: 'de', label: 'Germany' },
]

<Select
  value={value}
  options={options}
  onChange={setValue}
  placeholder="Select country"
/>

With Label

tsx
<Select
  label="Country"
  value={value}
  options={options}
  onChange={setValue}
/>

Variants

tsx
<Select variant="normal" value="" options={options} placeholder="Normal" />
<Select variant="error" value="" options={options} placeholder="Error" />

Sizes

tsx
<Select size="default" value="" options={options} placeholder="Default" />
<Select size="compact" value="" options={options} placeholder="Compact" />

Disabled Options

tsx
const options = [
  { value: 'active', label: 'Active' },
  { value: 'pending', label: 'Pending', disabled: true },
  { value: 'archived', label: 'Archived' },
]

<Select value="" options={options} placeholder="Select status" />

Full Width

tsx
<Select fullWidth value="" options={options} placeholder="Full width" />

With Message

tsx
<Select label="Country" variant="error" value="" options={options} message="Please select a country" />
<Select label="Region" value="" options={options} message="Optional field" />

Portal Rendering

For use inside containers with overflow: hidden:

tsx
<Select
  value={value}
  options={options}
  portalRenderNode={document.body}
/>

Props

PropTypeDefaultDescription
valuestringrequiredSelected value
optionsSelectOption[]requiredArray of options
onChange(value: string) => void-Change handler
labelstring-Label text
placeholderstring'Select...'Placeholder text
variant'normal' | 'error''normal'Visual variant
size'compact' | 'default''default'Select size
disabledbooleanfalseDisable select
fullWidthbooleanfalseFull width
messagestring-Message text below select (error, hint)
portalRenderNodeHTMLElement | null-Portal target for dropdown
classNamestring-CSS class name for the root element
classnamesSelectClassNames-Custom class names for inner elements
refRef<HTMLDivElement>-Ref to the root container element
data-test-idstring-Test identifier attribute

Option Type

tsx
type SelectOption = {
  value: string
  label: string
  disabled?: boolean
}

ClassNames

KeyDescription
labelLabel element
triggerTrigger button
dropdownDropdown container
optionIndividual option

Released under the MIT License.