Skip to content

Commit

Permalink
fix(cascader): fix Cascader add filter select the bug (#2674)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaixingOoO authored Dec 22, 2023
1 parent b2b254a commit 96fca5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/cascader/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { forwardRef, useMemo } from 'react';
import classNames from 'classnames';
import { ChevronRightIcon as TdChevronRightIcon } from 'tdesign-icons-react';

import isFunction from 'lodash/isFunction';
import TLoading from '../../loading';
import Checkbox from '../../checkbox';

Expand Down Expand Up @@ -114,14 +115,19 @@ const Item = forwardRef(
);
};

const isFiltering = useMemo(
() => Boolean(cascaderContext.filterable) || isFunction(cascaderContext.filter),
[cascaderContext.filterable, cascaderContext.filter],
);

return (
<li
ref={ref || setRefCurrent}
className={itemClass}
onClick={(e: React.MouseEvent) => {
e.stopPropagation();
e?.nativeEvent?.stopImmediatePropagation?.();

if (cascaderContext.inputVal && isFiltering) return;
onClick(node);
}}
onMouseEnter={(e: React.MouseEvent) => {
Expand Down
8 changes: 7 additions & 1 deletion src/cascader/core/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ export function valueChangeEffect(node: TreeNode, cascaderContext: CascaderConte
* @param cascaderContext
*/
export function closeIconClickEffect(cascaderContext: CascaderContextType) {
const { setVisible, multiple, setExpend, setValue } = cascaderContext;
const { setVisible, multiple, setExpend, setValue, treeStore } = cascaderContext;

const expanded = treeStore.getExpanded();
setTimeout(() => {
treeStore.replaceExpanded(expanded);
treeStore.refreshNodes();
}, 0);

setVisible(false, {});

Expand Down

0 comments on commit 96fca5b

Please sign in to comment.