Chakra React Select
chakra-react-select is a comprehensive wrapper that integrates the popular `react-select` component library with Chakra UI, providing accessible and customizable dropdown, combobox, and multi-select inputs. It is currently in version 6.1.1 and actively maintained, with frequent releases addressing bug fixes, dependency updates, and new features. The library closely follows major versions of Chakra UI, with v6 specifically introducing compatibility for Chakra UI v3. It differentiates itself by seamlessly blending the extensive feature set and customization capabilities of `react-select` with Chakra UI's styling system and accessibility principles, offering a unified developer experience. It also provides built-in support for theme integration, including color palettes and dark mode with `next-themes`.
Common errors
-
Error: @chakra-ui/react@2.x is not compatible with chakra-react-select@6.x
cause Using chakra-react-select v6 with an older version of Chakra UI (v2.x or earlier).fixUpgrade your `@chakra-ui/react` dependency to `3.x` to match the requirements of `chakra-react-select` v6. -
TypeError: Cannot read properties of undefined (reading 'styles') in Select
cause Attempting to directly use the `styles` prop from `react-select` without adapting it for Chakra UI, or an incorrect `chakraStyles` configuration.fixUse the `chakraStyles` prop for all styling customizations, which correctly integrates with Chakra UI's theme and style props. Avoid using `styles` directly. -
Property 'value' does not exist on type 'IntrinsicAttributes & SelectProps<Option, boolean, GroupBase<Option>>'
cause TypeScript error often due to incorrect type definitions for options or the `value` prop, or missing generic types for the `Select` component.fixEnsure your options array adheres to the `react-select` expected format (`{ value: string; label: string; }`) and provide generic types to the `Select` component, e.g., `<Select<Option, false> ... />` for single select or `<Select<Option, true> ... />` for multi-select.
Warnings
- breaking Version 6.0.0 introduces fundamental breaking changes to align with Chakra UI v3. Projects using older versions of Chakra UI (v1 or v2) must upgrade their Chakra UI dependency to v3 before upgrading to chakra-react-select v6.
- breaking The default `menuPlacement` property changed from a static position (e.g., 'bottom') to `'auto'` in v5.1.0 to match Chakra UI's popover behavior. This can affect layout if your application relied on the previous fixed placement.
- breaking In v6.1.0, the `selectedOptionColorPalette` now uses semantic tokens (`colorPalette.solid` and `colorPalette.contrast`) instead of direct numeric indices (`.300`, `.500`) for selected option background and text colors. This may alter the appearance of selected options.
- breaking The `isFixed` attribute on options, previously used to remove the tag close button, was deprecated and then fully removed in v5.0.1. Components relying on this prop will no longer function as expected.
- gotcha Strict peer dependency ranges are enforced for `react`, `@chakra-ui/react`, and `react-select`. Mismatched versions can lead to runtime errors, styling issues, or build failures.
Install
-
npm install chakra-react-select -
yarn add chakra-react-select -
pnpm add chakra-react-select
Imports
- Select
const Select = require('chakra-react-select')import Select from 'chakra-react-select';
- CreatableSelect
import CreatableSelect from 'chakra-react-select/CreatableSelect';
import { CreatableSelect } from 'chakra-react-select'; - AsyncSelect
import { AsyncSelect } from 'chakra-react-select/async';import { AsyncSelect } from 'chakra-react-select'; - ChakraStylesConfig
import { ChakraStylesConfig } from 'chakra-react-select';
Quickstart
import React, { useState } from 'react';
import Select from 'chakra-react-select';
import { ChakraProvider, extendTheme } from '@chakra-ui/react';
const theme = extendTheme({
colors: {
brand: {
50: '#E6FFFA',
100: '#B2F5EA',
200: '#81E6D9',
300: '#4FD1C5',
400: '#38B2AC',
500: '#319795',
600: '#2C7A7B',
700: '#285E61',
800: '#234E52',
900: '#1D4044'
}
}
});
interface Option {
value: string;
label: string;
}
const options: Option[] = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'cherry', label: 'Cherry' }
];
function App() {
const [selectedValue, setSelectedValue] = useState<Option | null>(null);
return (
<ChakraProvider theme={theme}>
<div style={{ padding: '20px', maxWidth: '400px', margin: 'auto' }}>
<Select
name="fruits"
options={options}
placeholder="Select a fruit..."
closeMenuOnSelect={true}
selectedOptionColorScheme="brand"
onChange={(newValue) => {
setSelectedValue(newValue as Option);
console.log('Selected value:', newValue);
}}
value={selectedValue}
/>
</div>
</ChakraProvider>
);
}
export default App;