Skip to content

Commit

Permalink
fix(SearchTree): 搜索到节点匹配时,展开所有下级节点 #594 (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr-z committed Mar 3, 2022
1 parent 4297d62 commit e84e2c8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/react-search-tree/src/index.tsx
Expand Up @@ -134,15 +134,14 @@ function SearchTree<V extends SearchTagInputOption>(props: SearchTreeProps<V>) {
};

const selectedSearch = (searchValue: string) => {
const hiddenNodeForSeach = (childrens: TreeData[]) => {
const hiddenNodeForSeach = (childrens: TreeData[], parentIsHide: boolean = true) => {
childrens.forEach((child: TreeData) => {
const isHide = !(child.label as string).includes(searchValue);
const isHide = !(child.label as string).includes(searchValue.trim()) && parentIsHide;
if (!!child.children?.length) {
hiddenNodeForSeach(child.children);
hiddenNodeForSeach(child.children, isHide);
const find = child.children.find((item) => !item.hideNode);
child.hideNode = isHide && !find;
} else {
// const isHide = !(child.label as string).includes(searchValue)
child.hideNode = isHide;
}
});
Expand All @@ -159,7 +158,7 @@ function SearchTree<V extends SearchTagInputOption>(props: SearchTreeProps<V>) {
<SearchTagInput
{...other}
emptyOption={isEmpty}
onSearch={debounce(selectedSearch, 700)}
onSearch={debounce(selectedSearch, 600)}
onChange={selectedChange}
values={selectedValues}
options={selectedOptions}
Expand Down

0 comments on commit e84e2c8

Please sign in to comment.