Skip to content

Commit

Permalink
Merge pull request #623 from jsonz1993/fix/cascader_visible
Browse files Browse the repository at this point in the history
fix(cascader):  filterable visible
  • Loading branch information
honkinglin authored Apr 14, 2022
2 parents 33854bc + 92c2776 commit 266c61f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/cascader/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const getTreeValue = (value: CascaderContextType['value']) => {
return treeValue;
};

/**
* 判断node是否在页面上
* @param node Node
*/
export function isInPage(node: Node) {
return node === document.body ? false : document.body.contains(node);
}

export default {
getFullPathLabel,
};
12 changes: 5 additions & 7 deletions src/cascader/utils/inputContent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import isFunction from 'lodash/isFunction';
import isEmpty from 'lodash/isEmpty';
import { TreeNode, CascaderContextType, TreeNodeValue, CascaderProps } from '../interface';
import { isInPage } from './helper';

/**
* icon Class
Expand Down Expand Up @@ -147,13 +148,10 @@ export function outerClickListenerEffect(
event: MouseEvent | TouchEvent,
) {
const { visible, setVisible } = cascaderContext;
if (!ref || ref.contains(event.target as Node)) {
return;
}

if (visible) {
setVisible(false);
}
const target = event.target as Node;
// 可能点击的dom在判断的时候已经被移除了
if (!visible || !ref || ref.contains(target) || !isInPage(target)) return;
setVisible(false);
}

/**
Expand Down

0 comments on commit 266c61f

Please sign in to comment.