项目作者: HelKyle

项目描述 :
A multiple cascader component for antd
高级语言: TypeScript
项目地址: git://github.com/HelKyle/antd-multi-cascader.git
创建时间: 2021-01-03T11:45:02Z
项目社区:https://github.com/HelKyle/antd-multi-cascader

开源协议:MIT License

下载


🎉🎉🎉 News

Antd@4.17.0 has supported multiple cascader features. Should consider it first.

antd-multi-cascader

Test PRs Welcome MIT license
Codecov Coverage
Storybook
npm

A multiple cascader component for antd

antd-multi-cascader

Online DemoHow it works?


demo

How to use?

  1. npm install antd-multi-cascader or yarn add antd-multi-cascader
  1. const [value, setValue] = React.useState<string[]>([]);
  2. return (
  3. <MultiCascader
  4. value={value}
  5. onChange={setValue}
  6. data={options}
  7. placeholder="Select Cities"
  8. ></MultiCascader>
  9. )

Props

🚨 Please install 1.3.0 version or set popupTransitionName=slide-up manually if your antd version below 4.13.0
🚨 如果你使用的 antd 版本小于 4.13.0,请安装 1.3.0 的版本,或手动设置 popupTransitionName=slide-up

Props Type Description
value string[] Selected value
data TreeNode[] Cascader options TreeNode { title: string, value: string, children?: TreeNode, isLeaf?: boolean }
allowClear boolean Whether allow clear
placeholder string The input placeholder
onChange (newVal) => void Callback when finishing value select
selectAll boolean Whether allow select all
className string The additional css class
style React.CSSProperties The additional style
disabled boolean Whether disabled select
okText string The text of the Confirm button
cancelText string The text of the Cancel button
selectAllText string The text of the SelectAll radio
onCascaderChange (node: TreeNode, operations: { add: (children: TreeNode[]) => TreeNode[] }) => void Trigger when click a menu item
popupTransitionName string Should set ‘slide-up’ manually if antd version below 4.13.0
getPopupContainer (props: any) => HTMLElement Parent Node which the selector should be rendered to. Default to body. When position issues happen, try to modify it into scrollable content and position it relative
maxTagCount Max tag count to show. responsive will cost render performance number \ responsive

Async Data Example

  1. const [asyncOptions, setAsyncOptions] = React.useState([
  2. {
  3. value: 'ParentNode1',
  4. title: 'ParentNode1',
  5. // tell component this node is not a leaf node
  6. isLeaf: false,
  7. },
  8. {
  9. value: 'ParentNode2',
  10. title: 'ParentNode2',
  11. },
  12. ])
  13. const handleCascaderChange = React.useCallback((node, { add }) => {
  14. // call add function to append children nodes
  15. if (node.value === 'ParentNode1' && !node.children) {
  16. setTimeout(() => {
  17. setAsyncOptions(
  18. add([
  19. {
  20. value: 'ParentNode1-1',
  21. title: 'ParentNode1-1',
  22. },
  23. ])
  24. )
  25. }, 1000)
  26. }
  27. }, [])
  28. <MultiCascader
  29. selectAll
  30. data={asyncOptions}
  31. onCascaderChange={handleCascaderChange}
  32. placeholder="Async Data"
  33. ></MultiCascader>