diff --git a/web/src/components/tree-select.tsx b/web/src/components/tree-select.tsx index 6dc770e4ce..4e90c0f861 100644 --- a/web/src/components/tree-select.tsx +++ b/web/src/components/tree-select.tsx @@ -145,11 +145,18 @@ export const TreeSelect = forwardRef( const titleMatch = node.title .toLowerCase() .includes(term.toLowerCase()); + // A matching parent keeps its entire subtree so its children stay + // visible; otherwise only branches containing matching descendants + // are kept. + if (titleMatch) { + acc.push(node); + return acc; + } const filteredChildren = node.children ? filterTree(node.children, term) : undefined; - if (titleMatch || filteredChildren?.length) { - acc.push({ ...node, children: filteredChildren ?? node.children }); + if (filteredChildren?.length) { + acc.push({ ...node, children: filteredChildren }); } return acc; }, []);