A Select control built with and for ReactJS that provides comprehensive dropdown functionality with support for single/multi-select, async data loading, search filtering, and extensive customization.
npx @tessl/cli install tessl/npm-react-select@5.10.0React-Select is a comprehensive and flexible select component library for React applications that provides a powerful, customizable dropdown interface with support for single and multi-select functionality, async data loading, search filtering, and custom option rendering. Built with TypeScript and Emotion for styling, it offers extensive customization through component injection APIs, controllable state props, and a modular architecture.
npm install react-selectimport Select from "react-select";
import AsyncSelect from "react-select/async";
import CreatableSelect from "react-select/creatable";
import AsyncCreatableSelect from "react-select/async-creatable";
import makeAnimated from "react-select/animated";
import { components, createFilter, mergeStyles, defaultTheme } from "react-select";For CommonJS:
const Select = require("react-select").default;
const AsyncSelect = require("react-select/async").default;
const CreatableSelect = require("react-select/creatable").default;
const AsyncCreatableSelect = require("react-select/async-creatable").default;
const makeAnimated = require("react-select/animated").default;
const { components, createFilter, mergeStyles, defaultTheme } = require("react-select");import Select from "react-select";
interface Option {
value: string;
label: string;
}
const options: Option[] = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
];
function MyComponent() {
const [selectedOption, setSelectedOption] = useState<Option | null>(null);
return (
<Select
value={selectedOption}
onChange={setSelectedOption}
options={options}
placeholder="Select a flavor..."
isSearchable
/>
);
}React-Select is built around several key architectural components:
useStateManager) or controllable props for external stateMain select component variants providing different interaction patterns and capabilities.
function Select<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
props: Props<Option, IsMulti, Group>
): JSX.Element;
function AsyncSelect<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
props: Props<Option, IsMulti, Group> & AsyncProps<Option>
): JSX.Element;
function CreatableSelect<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
props: Props<Option, IsMulti, Group> & CreatableProps<Option>
): JSX.Element;
function AsyncCreatableSelect<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
props: Props<Option, IsMulti, Group> & AsyncProps<Option> & CreatableProps<Option>
): JSX.Element;Async data loading capabilities for dynamic option fetching with caching and loading state management.
interface AsyncProps<Option> {
defaultOptions?: OptionsOrGroups<Option, Group> | boolean;
cacheOptions?: any;
loadOptions?: (inputValue: string, callback: Function) => Promise<OptionsOrGroups<Option, Group>>;
}Comprehensive component customization system allowing replacement or modification of any UI element.
interface SelectComponentsConfig<Option, IsMulti extends boolean, Group extends GroupBase<Option>> {
ClearIndicator?: ComponentType<ClearIndicatorProps<Option, IsMulti, Group>>;
Control?: ComponentType<ControlProps<Option, IsMulti, Group>>;
DropdownIndicator?: ComponentType<DropdownIndicatorProps<Option, IsMulti, Group>>;
DownChevron?: ComponentType<any>;
CrossIcon?: ComponentType<any>;
Group?: ComponentType<GroupProps<Option, IsMulti, Group>>;
GroupHeading?: ComponentType<GroupHeadingProps<Option, IsMulti, Group>>;
IndicatorsContainer?: ComponentType<IndicatorsContainerProps<Option, IsMulti, Group>>;
IndicatorSeparator?: ComponentType<IndicatorSeparatorProps<Option, IsMulti, Group>>;
Input?: ComponentType<InputProps<Option, IsMulti, Group>>;
LoadingIndicator?: ComponentType<LoadingIndicatorProps<Option, IsMulti, Group>>;
Menu?: ComponentType<MenuProps<Option, IsMulti, Group>>;
MenuList?: ComponentType<MenuListProps<Option, IsMulti, Group>>;
MenuPortal?: ComponentType<MenuPortalProps<Option, IsMulti, Group>>;
LoadingMessage?: ComponentType<NoticeProps<Option, IsMulti, Group>>;
NoOptionsMessage?: ComponentType<NoticeProps<Option, IsMulti, Group>>;
MultiValue?: ComponentType<MultiValueProps<Option, IsMulti, Group>>;
MultiValueContainer?: ComponentType<MultiValueGenericProps<Option, IsMulti, Group>>;
MultiValueLabel?: ComponentType<MultiValueGenericProps<Option, IsMulti, Group>>;
MultiValueRemove?: ComponentType<MultiValueRemoveProps<Option, IsMulti, Group>>;
Option?: ComponentType<OptionProps<Option, IsMulti, Group>>;
Placeholder?: ComponentType<PlaceholderProps<Option, IsMulti, Group>>;
SelectContainer?: ComponentType<ContainerProps<Option, IsMulti, Group>>;
SingleValue?: ComponentType<SingleValueProps<Option, IsMulti, Group>>;
ValueContainer?: ComponentType<ValueContainerProps<Option, IsMulti, Group>>;
}Complete type system supporting generic Option and Group types with full TypeScript integration.
interface GroupBase<Option> {
readonly options: readonly Option[];
readonly label?: string;
}
type Options<Option> = readonly Option[];
type SingleValue<Option> = Option | null;
type MultiValue<Option> = readonly Option[];
type OnChangeValue<Option, IsMulti extends boolean> = IsMulti extends true ? MultiValue<Option> : SingleValue<Option>;
interface ActionMeta<Option> {
action: 'select-option' | 'deselect-option' | 'remove-value' | 'pop-value' | 'set-value' | 'clear' | 'create-option';
name?: string;
option?: Option;
removedValue?: Option;
removedValues?: Option[];
}Animated components system providing smooth transitions for multi-select values and other UI elements.
function makeAnimated(
externalComponents?: Partial<SelectComponentsGeneric>
): Partial<SelectComponentsGeneric>;
interface AnimatedComponents {
Input: ComponentType<InputProps<any, any, any>>;
MultiValue: ComponentType<MultiValueProps<any, any, any>>;
Placeholder: ComponentType<PlaceholderProps<any, any, any>>;
SingleValue: ComponentType<SingleValueProps<any, any, any>>;
ValueContainer: ComponentType<ValueContainerProps<any, any, any>>;
}Core hooks for state management and advanced component integration.
function useStateManager<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
props: StateManagerProps<Option, IsMulti, Group>
): StateManagerReturn<Option, IsMulti, Group>;
function useAsync<Option>(
props: AsyncProps<Option>
): AsyncState<Option>;
function useCreatable<Option>(
props: CreatableProps<Option>
): CreatableState<Option>;Factory function for creating custom filter functions with configurable matching behavior.
function createFilter<Option>(config?: FilterConfig<Option>): FilterFunction<Option>;
interface FilterConfig<Option> {
ignoreCase?: boolean;
ignoreAccents?: boolean;
stringify?: (option: FilterOptionOption<Option>) => string;
trim?: boolean;
matchFrom?: 'any' | 'start';
}Utility for merging style configurations with deep object merging.
function mergeStyles<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(
source: StylesConfig<Option, IsMulti, Group>,
target: StylesConfig<Option, IsMulti, Group>
): StylesConfig<Option, IsMulti, Group>;CSP nonce provider component for secure style injection.
function NonceProvider({ nonce, children }: { nonce: string; children: ReactNode }): JSX.Element;Object containing all individual Select sub-components for granular customization.
const components: {
ClearIndicator: ComponentType<ClearIndicatorProps<any, any, any>>;
Control: ComponentType<ControlProps<any, any, any>>;
DropdownIndicator: ComponentType<DropdownIndicatorProps<any, any, any>>;
Input: ComponentType<InputProps<any, any, any>>;
Menu: ComponentType<MenuProps<any, any, any>>;
Option: ComponentType<OptionProps<any, any, any>>;
// ... 25+ total components
};Default theme configuration object with colors and spacing definitions.
const defaultTheme: {
colors: Colors;
spacing: ThemeSpacing;
};
interface Colors {
primary: string;
primary75: string;
primary50: string;
primary25: string;
danger: string;
dangerLight: string;
neutral0: string;
// ... additional color definitions
}
interface ThemeSpacing {
baseUnit: number;
controlHeight: number;
menuGutter: number;
}