|
@@ -138,7 +138,11 @@ import { Cascader } from '@douyinfe/semi-ui';
|
|
|
|
|
|
### Searchable
|
|
|
|
|
|
-Use `filterTreeNode` to support search input. By default it searches the `value` property of the data. You can use `treeNodeFilterProp` to set another property to search or pass in a function to `filterTreeNode` to customize search behavior.
|
|
|
+Use `filterTreeNode` to support search input.
|
|
|
+
|
|
|
+By default, the `label` value is searched (using the includes method of the string for matching, case-insensitive). You can specify other attribute values through `treeNodeFilterProp` to search. For example, If `label` is ReactNode, you can use other fields in treeData to store plain text, and specify the field for search through `treeNodeFilterProp`.
|
|
|
+
|
|
|
+The default search results will only display the paths of leaf nodes. If you want to display more results, you can set `filterLeafOnly` to `false`.
|
|
|
|
|
|
```jsx live=true
|
|
|
import React from 'react';
|
|
@@ -184,10 +188,56 @@ import { Cascader } from '@douyinfe/semi-ui';
|
|
|
}
|
|
|
],
|
|
|
}];
|
|
|
+ const labelNodeTreeData = [{
|
|
|
+ label: <Tooltip content="Other info">Impressionism</Tooltip>,
|
|
|
+ labelText: 'Impressionism',
|
|
|
+ value: 'impressionism',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Visual Arts</Tooltip>,
|
|
|
+ labelText: 'Visual Arts',
|
|
|
+ value: 'visualArts',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Claude Monet</Tooltip>,
|
|
|
+ labelText: 'Claude Monet',
|
|
|
+ value: 'Monet',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">'Pierre-Auguste Renoir</Tooltip>,
|
|
|
+ labelText: 'Pierre-Auguste Renoir',
|
|
|
+ value: 'Renoir',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Édouard Manet</Tooltip>,
|
|
|
+ labelText: 'Édouard Manet',
|
|
|
+ value: 'Manet',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Music</Tooltip>,
|
|
|
+ labelText: 'Music',
|
|
|
+ value: 'music',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Claude Debussy</Tooltip>,
|
|
|
+ labelText: 'Claude Debussy',
|
|
|
+ value: 'Debussy',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: <Tooltip content="Other info">Maurice Ravel</Tooltip>,
|
|
|
+ labelText: 'Maurice Ravel',
|
|
|
+ value: 'Ravel',
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ }];
|
|
|
return (
|
|
|
<div>
|
|
|
<Cascader
|
|
|
- style={{ width: 400 }}
|
|
|
+ style={{ width: 300 }}
|
|
|
treeData={treeData}
|
|
|
placeholder="Search in label by default"
|
|
|
filterTreeNode
|
|
@@ -195,12 +245,32 @@ import { Cascader } from '@douyinfe/semi-ui';
|
|
|
<br/>
|
|
|
<br/>
|
|
|
<Cascader
|
|
|
- style={{ width: 400 }}
|
|
|
+ style={{ width: 300 }}
|
|
|
treeData={treeData}
|
|
|
placeholder="Search in value"
|
|
|
filterTreeNode
|
|
|
treeNodeFilterProp='value'
|
|
|
/>
|
|
|
+ <br/>
|
|
|
+ <br/>
|
|
|
+ <Typography.Title heading={6}>filterLeafOnly=false:</Typography.Title>
|
|
|
+ <Cascader
|
|
|
+ style={{ width: 300 }}
|
|
|
+ treeData={treeData}
|
|
|
+ placeholder="filterLeafOnly=false"
|
|
|
+ filterTreeNode
|
|
|
+ filterLeafOnly={false}
|
|
|
+ />
|
|
|
+ <br/>
|
|
|
+ <br/>
|
|
|
+ <Typography.Title heading={6}>Label is ReactNode, specify other attributes to search</Typography.Title>
|
|
|
+ <Cascader
|
|
|
+ style={{ width: 300 }}
|
|
|
+ treeData={labelNodeTreeData}
|
|
|
+ placeholder="Search for labelText"
|
|
|
+ filterTreeNode
|
|
|
+ treeNodeFilterProp='labelText'
|
|
|
+ />
|
|
|
</div>
|
|
|
);
|
|
|
};
|