React Headless Select Component

14.16.8 · active · verified Tue Apr 21

rc-select is a foundational, unstyled React component designed for building highly customizable select input fields. It provides a robust set of core functionalities, including single and multiple selection modes, search capabilities, and comprehensive dropdown management, without dictating any specific UI or styling framework. The current stable version, as per npm metadata, is 14.16.8, though associated projects under `@rc-component/select` show frequent patch releases, indicating active development and maintenance primarily focused on bug fixes and stability. This library serves as a powerful primitive, famously underpinning the `Select` component within major UI libraries like Ant Design. Its key differentiator is its headless architecture, granting developers complete control over the rendering of internal elements and visual presentation, making it an excellent choice for applications requiring highly custom designs and strict adherence to accessibility standards.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the Select component with single and multiple selection, including controlled and uncontrolled examples, and necessary CSS import.

import React, { useState } from 'react';
import Select, { Option } from 'rc-select';
import 'rc-select/assets/index.css';

const MySelectComponent = () => {
  const [value, setValue] = useState('lucy');

  const handleChange = (newValue) => {
    console.log(`Selected: ${newValue}`);
    setValue(newValue);
  };

  return (
    <div style={{ width: 200, margin: '20px auto' }}>
      <h3>Basic Select</h3>
      <Select
        value={value}
        onChange={handleChange}
        placeholder="Please select..."
        style={{ width: '100%' }}
      >
        <Option value="jack">Jack</Option>
        <Option value="lucy">Lucy</Option>
        <Option value="yiminghe">Yiminghe</Option>
        <Option value="disabled" disabled>Disabled Option</Option>
      </Select>
      <h3 style={{ marginTop: '20px' }}>Multiple Select</h3>
      <Select
        mode="multiple"
        defaultValue={['a10', 'c12']}
        placeholder="Select multiple..."
        style={{ width: '100%' }}
        onChange={(values) => console.log('Multiple selected:', values)}
      >
        <Option value="a10">a10</Option>
        <Option value="c12">c12</Option>
        <Option value="b11">b11</Option>
      </Select>
    </div>
  );
};

export default MySelectComponent;

view raw JSON →