Skip to content

Commit 945f128

Browse files
committed
feat: improve flatten treeData
1 parent 750de00 commit 945f128

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/OptionList.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,16 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
162162
nodes: EventDataNode<any>[],
163163
searchVal?: string,
164164
): EventDataNode<any> | null => {
165-
// Flatten the tree structure
166-
const flattenedNodes = flattenTreeData(nodes, true, fieldNames);
165+
// 使用 mergedExpandedKeys 而不是 true
166+
// 这样可以保持与实际展示状态一致
167+
const flattenedNodes = flattenTreeData(
168+
nodes,
169+
// 搜索时展开所有节点以便搜索,否则使用当前展开状态
170+
searchVal ? true : mergedExpandedKeys,
171+
fieldNames,
172+
);
167173

168-
// Iterate through the flattened array to find the first matching node
174+
// 查找第一个匹配的节点
169175
const matchedNode = flattenedNodes.find(node => {
170176
const rawNode = node.data as EventDataNode<any>;
171177
if (rawNode.disabled || rawNode.selectable === false) {

0 commit comments

Comments
 (0)