rc-cascader (Legacy)

3.34.0 · deprecated · verified Tue Apr 21

This package, `rc-cascader`, is a foundational React UI component providing a robust and unstyled cascader (hierarchical select) control. Its latest official release under this name is version 3.34.0. While stable for existing applications, new development should strongly consider migrating to its successor, `@rc-component/cascader`, which is the actively maintained and refactored version of this component (starting with `@rc-component/cascader` v1.8.0). `rc-cascader` emphasizes core functionality and accessibility, providing the logic for hierarchical selection without imposing specific styling, making it highly adaptable for integration into custom design systems like Ant Design. It depends on `react` and `react-dom` versions 16.9.0 or higher.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to render a basic Cascader component with static hierarchical options, using an input field as the trigger. It requires a root HTML element with `id="root"`.

import React from 'react';
import ReactDOM from 'react-dom';
import Cascader from 'rc-cascader';

const options = [{
  'label': '福建',
  'value': 'fj',
  'children': [{
    'label': '福州',
    'value': 'fuzhou',
    'children': [{
      'label': '马尾',
      'value': 'mawei',
    }],
  }, {
    'label': '泉州',
    'value': 'quanzhou',
  }],
}, {
  'label': '浙江',
  'value': 'zj',
  'children': [{
    'label': '杭州',
    'value': 'hangzhou',
    'children': [{
      'label': '余杭',
      'value': 'yuhang',
    }],
  }],
}, {
  'label': '北京',
  'value': 'bj',
  'children': [{
    'label': '朝阳区',
    'value': 'chaoyang',
  }, {
    'label': '海淀区',
    'value': 'haidian',
  }],
}];

const App = () => (
  <div style={{ padding: 20 }}>
    <h2>Cascader Example</h2>
    <Cascader options={options} placeholder="Please select">
      <input style={{ width: 200, padding: 8, borderRadius: 4, border: '1px solid #ccc' }} readOnly value="Select region" />
    </Cascader>
  </div>
);

ReactDOM.render(<App />, document.getElementById('root'));

view raw JSON →