1.1.1 • Published 3 years ago

weike-multi-cascader v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

weike-multi-cascader

Online DemoHow it works?

How to use?

npm install react-multi-cascader or yarn add  react-multi-cascader
const [value, setValue] = React.useState<string[]>([]);

return (
  <MultiCascader
    value={value}
    onChange={setValue}
    data={options}
    placeholder="Select Cities"
  />
)

Props

PropsTypeDescription
valuestring[]Selected value
dataTreeNode[]Cascader options TreeNode { title: string, value: string, children?: TreeNode, isLeaf?: boolean }
allowClearbooleanWhether allow clear
placeholderstringThe input placeholder
onChange(newVal) => voidCallback when finishing value select
selectAllbooleanWhether allow select all
classNamestringThe additional css class
showBottomboolean是否显示底部确认组件
fristColumMultiboolean第一栏是否可选
isToolTipboolean已选内容是否通过tooltip显示
styleReact.CSSPropertiesThe additional style
disabledbooleanWhether disabled select
okTextstringThe text of the Confirm button
cancelTextstringThe text of the Cancel button
selectAllTextstringThe text of the SelectAll radio
onCascaderChange(node: TreeNode, operations: { add: (children: TreeNode[]) => TreeNode[] }) => voidTrigger when click a menu item
popupTransitionNamestringShould set 'ant-slide-up' manually if antd version greater than 4.13.0
getPopupContainer(props: any) => HTMLElementParent 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
maxTagCountMax tag count to show. responsive will cost render performancenumber | responsive

Async Data Example

const [asyncOptions, setAsyncOptions] = React.useState([
  {
    value: 'ParentNode1',
    title: 'ParentNode1',
    // tell component this node is not a leaf node
    isLeaf: false,
  },
  {
    value: 'ParentNode2',
    title: 'ParentNode2',
  },
])

const handleCascaderChange = React.useCallback((node, { add }) => {
  // call add function to append children nodes
  if (node.value === 'ParentNode1' && !node.children) {
    setTimeout(() => {
      setAsyncOptions(
        add([
          {
            value: 'ParentNode1-1',
            title: 'ParentNode1-1',
          },
        ])
      )
    }, 1000)
  }
}, [])

    <MultiCascader
        selectAll
        data={options}
        value={state}
        onChange={(v,v1) => onChange(v, v1)}
        disabled={disabled}
        placeholder="Default"
        style={{ width: '320px' }}
        showBottom={true}
        fristColumMulti={true}
        isToolTip={true}
    />