Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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;
1 change: 0 additions & 1 deletion src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
mergedFieldNames,
dropdownPrefixCls || prefixCls,
searchConfig,
changeOnSelect,
Comment thread
crazyair marked this conversation as resolved.
);

// =========================== Values ===========================
Expand Down
6 changes: 2 additions & 4 deletions src/OptionList/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface ColumnProps<OptionType extends DefaultOptionType = DefaultOptio
halfCheckedSet: Set<React.Key>;
loadingKeys: React.Key[];
isSelectable: (option: DefaultOptionType) => boolean;
searchValue?: string;
}

export default function Column<OptionType extends DefaultOptionType = DefaultOptionType>({
Expand All @@ -39,7 +38,6 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
halfCheckedSet,
loadingKeys,
isSelectable,
searchValue,
}: ColumnProps<OptionType>) {
const menuPrefixCls = `${prefixCls}-menu`;
const menuItemPrefixCls = `${prefixCls}-menu-item`;
Expand Down Expand Up @@ -117,7 +115,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
}) => {
// >>>>> Open
const triggerOpenPath = () => {
if (disabled || searchValue) {
if (disabled) {
return;
}
const nextValueCells = [...fullPath];
Expand Down Expand Up @@ -189,7 +187,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
halfChecked={halfChecked}
disabled={disabled || disableCheckbox}
disableCheckbox={disableCheckbox}
onClick={(e: React.MouseEvent<HTMLSpanElement>) => {
onClick={e => {
if (disableCheckbox) {
return;
}
Expand Down
8 changes: 1 addition & 7 deletions src/OptionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import type { DefaultOptionType, SingleValueType } from '../Cascader';
import CascaderContext from '../context';
import {
getFullPathKeys,
isLeaf,
scrollIntoParentView,
toPathKey,
Expand Down Expand Up @@ -128,14 +127,10 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
const optionList = [{ options: mergedOptions }];
let currentList = mergedOptions;

const fullPathKeys = getFullPathKeys(currentList, fieldNames);

for (let i = 0; i < activeValueCells.length; i += 1) {
const activeValueCell = activeValueCells[i];
const currentOption = currentList.find(
(option, index) =>
(fullPathKeys[index] ? toPathKey(fullPathKeys[index]) : option[fieldNames.value]) ===
activeValueCell,
option => option[fieldNames.value] === activeValueCell,
);

const subOptions = currentOption?.[fieldNames.children];
Expand Down Expand Up @@ -213,7 +208,6 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
<Column
key={index}
{...columnProps}
searchValue={searchValue}
prefixCls={mergedPrefixCls}
options={col.options}
prevValuePath={prevValuePath}
Expand Down
40 changes: 14 additions & 26 deletions src/hooks/useSearchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default (
fieldNames: InternalFieldNames,
prefixCls: string,
config: ShowSearchType,
changeOnSelect?: boolean,
) => {
const { filter = defaultFilter, render = defaultRender, limit = 50, sort } = config;

Expand All @@ -42,30 +41,19 @@ export default (
const mergedDisabled = parentDisabled || option.disabled;

// If current option is filterable
if (
// If is leaf option
!children ||
children.length === 0 ||
// If is changeOnSelect
changeOnSelect
) {
if (filter(search, connectedPathOptions, { label: fieldNames.label })) {
filteredOptions.push({
...option,
disabled: mergedDisabled,
[fieldNames.label as 'label']: render(
search,
connectedPathOptions,
prefixCls,
fieldNames,
),
[SEARCH_MARK]: connectedPathOptions,
[fieldNames.children]: undefined,
});
}
}

if (children) {
if (filter(search, connectedPathOptions, { label: fieldNames.label })) {
filteredOptions.push({
...option,
disabled: mergedDisabled,
[fieldNames.label as 'label']: render(
search,
connectedPathOptions,
prefixCls,
fieldNames,
),
[SEARCH_MARK]: connectedPathOptions,
});
} else if (children) {
dig(
option[fieldNames.children] as DefaultOptionType[],
connectedPathOptions,
Expand All @@ -87,5 +75,5 @@ 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, filter, sort, limit]);
};