Socket
Socket
Sign inDemoInstall

rc-cascader

Package Overview
Dependencies
20
Maintainers
5
Versions
161
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-cascader

cascade select ui component for react


Version published
Weekly downloads
1M
decreased by-16.34%
Maintainers
5
Install size
2.06 MB
Created
Weekly downloads
 

Package description

What is rc-cascader?

The rc-cascader package is a React component for creating cascading drop-down menus. It allows users to select options from a hierarchical structure, which is useful for selecting nested categories or locations.

What are rc-cascader's main functionalities?

Basic Cascading Menu

This code sample demonstrates how to create a basic cascading menu with the rc-cascader package. The 'options' array defines the hierarchical structure of the menu, and the 'onChange' function logs the selected value.

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

const options = [
  {
    value: 'zhejiang',
    label: 'Zhejiang',
    children: [
      {
        value: 'hangzhou',
        label: 'Hangzhou',
        children: [
          {
            value: 'xihu',
            label: 'West Lake',
          },
        ],
      },
    ],
  },
  {
    value: 'jiangsu',
    label: 'Jiangsu',
    children: [
      {
        value: 'nanjing',
        label: 'Nanjing',
        children: [
          {
            value: 'zhonghuamen',
            label: 'Zhong Hua Men',
          },
        ],
      },
    ],
  },
];

function onChange(value) {
  console.log(value);
}

const App = () => (
  <Cascader options={options} onChange={onChange} />
);

export default App;

Custom Trigger

This code sample shows how to use a custom trigger, such as a button, to open the cascading menu. The children of the Cascader component determine the trigger element.

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

const options = [/* ... */];

const App = () => (
  <Cascader options={options}>
    <button>Click me to select</button>
  </Cascader>
);

export default App;

Search and Filter

This code sample illustrates how to enable a search and filter functionality within the cascading menu by setting the 'showSearch' prop to true. This allows users to quickly find options by typing.

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

const options = [/* ... */];

const App = () => (
  <Cascader options={options} showSearch />
);

export default App;

Other packages similar to rc-cascader

Readme

Source

rc-cascader

React Cascader Component

NPM version npm download build status Codecov bundle size dumi

Browser Support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Electron
Electron
IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

Screenshots

Example

https://cascader-react-component.vercel.app

Install

rc-cascader

$ npm install rc-cascader --save

Usage

import React from 'react';
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',
  }],
}];

React.render(
  <Cascader options={options}>
    ...
  </Cascader>
, container);

API

props

nametypedefaultdescription
autoClearSearchValuebooleantrueWhether the current search will be cleared on selecting an item. Only applies when checkable
optionsObjectThe data options of cascade
valueArrayselected value
defaultValueArrayinitial selected value
onChangeFunction(value, selectedOptions)callback when finishing cascader select
changeOnSelectBooleanfalsechange value on each selection
loadDataFunction(selectedOptions)callback when click any option, use for loading more options
expandTriggerString'click'expand current item when click or hover
openBooleanvisibility of popup overlay
onDropdownVisibleChangeFunction(visible)callback when popup overlay's visibility changed
transitionNameStringtransition className like "slide-up"
prefixClsStringrc-cascaderprefix className of popup overlay
dropdownClassNameStringadditional className of popup overlay
popupPlacementStringbottomLeftuse preset popup align config from builtinPlacements:bottomRight topRight bottomLeft topLeft
getPopupContainerfunction(trigger:Node):Node() => document.bodycontainer which popup select menu rendered into
dropdownMenuColumnStyleObjectstyle object for each cascader pop menu
fieldNamesObject{ label: 'label', value: 'value', children: 'children' }custom field name for label and value and children
expandIconReactNode>specific the default expand icon
loadingIconReactNode>specific the default loading icon
hidePopupOnSelectBoolean>truehide popup on select

option

nametypedefaultdescription
labelStringoption text to display
valueStringoption value as react key
disabledBooleandisabled option
childrenArraychildren options

Development

$ npm install
$ npm start

Test Case

$ npm test

Coverage

$ npm run coverage

License

rc-cascader is released under the MIT license.

Keywords

FAQs

Last updated on 12 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc