Uiplex

Select

A custom dropdown select component with single and multi-select modes, search functionality, and validation support. Features a dropdown menu that appears below the trigger, similar to Ant Design.

Basic Usage

import { Select } from 'uiplex';

<Select
  placeholder="Select an option"
  options={[
    { value: 'option1', label: 'Option 1' },
    { value: 'option2', label: 'Option 2' },
    { value: 'option3', label: 'Option 3' },
  ]}
  value={value}
  onChange={(value) => setValue(value)}
/>

Multi-Select

<Select
  mode="multiple"
  placeholder="Select multiple options"
  options={options}
  value={values}
  onChange={(values) => setValues(values)}
/>

<Select
  mode="multiple"
  placeholder="Select multiple countries"
  options={countries}
  allowClear
/>

Searchable

<Select
  searchable
  placeholder="Search and select..."
  options={countries}
/>

<Select
  mode="multiple"
  searchable
  placeholder="Search and select multiple..."
  options={countries}
/>

Sizes

<Select size="sm" placeholder="Small select" options={options} />
<Select size="md" placeholder="Medium select" options={options} />
<Select size="lg" placeholder="Large select" options={options} />

Variants

<Select variant="outline" placeholder="Outline" options={options} />
<Select variant="filled" placeholder="Filled" options={options} />
<Select variant="unstyled" placeholder="Unstyled" options={options} />

With FormControl

import { Select, FormControl, FormLabel, FormErrorMessage } from 'uiplex';

<FormControl isInvalid={hasError} isRequired id="country-field">
  <FormLabel>Country</FormLabel>
  <Select
    placeholder="Select a country"
    options={countries}
    value={country}
    onChange={(value) => setCountry(value)}
  />
  <FormErrorMessage>Country is required</FormErrorMessage>
</FormControl>

States

<Select placeholder="Normal select" options={options} />
<Select isDisabled placeholder="Disabled select" options={options} />
<Select isReadOnly placeholder="Read only" options={options} value="option1" />
<Select isInvalid placeholder="Invalid select" options={options} />

With Disabled Options

<Select
  placeholder="Select an option"
  options={[
    { value: 'option1', label: 'Available Option 1' },
    { value: 'option2', label: 'Available Option 2' },
    { value: 'option3', label: 'Disabled Option', disabled: true },
    { value: 'option4', label: 'Available Option 3' },
  ]}
/>

API Reference

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Size of the select
variant"outline" | "filled" | "unstyled""outline"Visual style variant
optionsSelectOption[][]Array of option objects
placeholderstring"Select..."Placeholder text shown when no option is selected
valuestring | number | (string | number)[]-Controlled value (single or array for multi-select)
defaultValuestring | number | (string | number)[]-Default value (uncontrolled)
onChange(value) => void-Callback when value changes
mode"single" | "multiple""single"Single or multi-select mode
searchablebooleanfalseEnable search functionality
allowClearbooleanfalseShow clear button when value is selected
widthstring | number-Width of the select component (e.g., "300px", 300, "100%")
isInvalidbooleanfalseWhether the select is invalid
isDisabledbooleanfalseWhether the select is disabled
isReadOnlybooleanfalseWhether the select is read-only
classNamestring""Additional CSS classes
styleReact.CSSProperties-Inline styles
...propsReact.SelectHTMLAttributes-All standard HTML select attributes

SelectOption Type

PropertyTypeDescription
valuestring | numberOption value
labelstringOption display text
disabledbooleanWhether the option is disabled