Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/demo/multiple-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: multiple-search
nav:
title: Demo
path: /demo
---

<code src="../../examples/multiple-search.tsx"></code>
48 changes: 48 additions & 0 deletions examples/multiple-search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import '../assets/index.less';
import Cascader from '../src';

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

const Demo = () => {
return <Cascader checkable showSearch options={options} />;
};

export default Demo;
2 changes: 1 addition & 1 deletion src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
mergedFieldNames,
dropdownPrefixCls || prefixCls,
searchConfig,
changeOnSelect,
Comment thread
crazyair marked this conversation as resolved.
changeOnSelect || multiple,
);

// =========================== Values ===========================
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useSearchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const defaultFilter: ShowSearchType['filter'] = (search, options, { label = '' }
const defaultRender: ShowSearchType['render'] = (inputValue, path, prefixCls, fieldNames) =>
path.map(opt => opt[fieldNames.label as string]).join(' / ');

export default (
const useSearchOptions = (
search: string,
options: DefaultOptionType[],
fieldNames: InternalFieldNames,
prefixCls: string,
config: ShowSearchType,
changeOnSelect?: boolean,
enableHalfPath?: boolean,
Comment thread
crazyair marked this conversation as resolved.
) => {
const { filter = defaultFilter, render = defaultRender, limit = 50, sort } = config;

Expand Down Expand Up @@ -46,8 +46,8 @@ export default (
// If is leaf option
!children ||
children.length === 0 ||
// If is changeOnSelect
changeOnSelect
// If is changeOnSelect or multiple
enableHalfPath
) {
if (filter(search, connectedPathOptions, { label: fieldNames.label })) {
filteredOptions.push({
Expand Down Expand Up @@ -87,5 +87,7 @@ export default (
return limit !== false && limit > 0
? filteredOptions.slice(0, limit as number)
: filteredOptions;
}, [search, options, fieldNames, prefixCls, render, changeOnSelect, filter, sort, limit]);
}, [search, options, fieldNames, prefixCls, render, enableHalfPath, filter, sort, limit]);
};

export default useSearchOptions;