Skip to content

Commit 644bf9d

Browse files
committed
chore: adjust code style
1 parent b99d2fb commit 644bf9d

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/OptionList.tsx

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -92,53 +92,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
9292
};
9393
}, [checkable, checkedKeys, halfCheckedKeys]);
9494

95-
// ========================== Get First Selectable Node ==========================
96-
const getFirstMatchingNode = (
97-
nodes: EventDataNode<any>,
98-
predicate: (node: EventDataNode<any>) => boolean,
99-
): EventDataNode<any> | null => {
100-
for (const node of nodes) {
101-
if (predicate(node)) {
102-
return node;
103-
}
104-
if (node[fieldNames.children]) {
105-
const matchInChildren = getFirstMatchingNode(node[fieldNames.children], predicate);
106-
if (matchInChildren) {
107-
return matchInChildren;
108-
}
109-
}
110-
}
111-
return null;
112-
};
113-
114-
const getFirstSelectableNode = (nodes: EventDataNode<any>): EventDataNode<any> | null =>
115-
getFirstMatchingNode(nodes, node => node.selectable !== false && !node.disabled);
116-
117-
const getFirstMatchNode = (nodes: EventDataNode<any>): EventDataNode<any> | null =>
118-
getFirstMatchingNode(nodes, node => filterTreeNode(node) && !node.disabled);
119-
120-
// ========================== Active Key Effect ==========================
121-
React.useEffect(() => {
122-
if (searchValue) {
123-
const firstMatchNode = getFirstMatchNode(memoTreeData);
124-
setActiveKey(firstMatchNode ? firstMatchNode[fieldNames.value] : null);
125-
return;
126-
}
127-
128-
if (open) {
129-
if (!multiple && checkedKeys.length) {
130-
setActiveKey(checkedKeys[0]);
131-
} else {
132-
const firstSelectableNode = getFirstSelectableNode(memoTreeData);
133-
if (firstSelectableNode) {
134-
setActiveKey(firstSelectableNode[fieldNames.value]);
135-
}
136-
}
137-
return;
138-
}
139-
setActiveKey(null);
140-
}, [open, searchValue]);
141-
14295
// ========================== Scroll Effect ==========================
14396
React.useEffect(() => {
14497
if (open && !multiple && checkedKeys.length) {
@@ -203,6 +156,53 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
203156
}
204157
}, [searchValue]);
205158

159+
// ========================== Get First Selectable Node ==========================
160+
const getFirstMatchingNode = (
161+
nodes: EventDataNode<any>,
162+
predicate: (node: EventDataNode<any>) => boolean,
163+
): EventDataNode<any> | null => {
164+
for (const node of nodes) {
165+
if (predicate(node)) {
166+
return node;
167+
}
168+
if (node[fieldNames.children]) {
169+
const matchInChildren = getFirstMatchingNode(node[fieldNames.children], predicate);
170+
if (matchInChildren) {
171+
return matchInChildren;
172+
}
173+
}
174+
}
175+
return null;
176+
};
177+
178+
const getFirstSelectableNode = (nodes: EventDataNode<any>): EventDataNode<any> | null =>
179+
getFirstMatchingNode(nodes, node => node.selectable !== false && !node.disabled);
180+
181+
const getFirstMatchNode = (nodes: EventDataNode<any>): EventDataNode<any> | null =>
182+
getFirstMatchingNode(nodes, node => filterTreeNode(node) && !node.disabled);
183+
184+
// ========================== Active Key Effect ==========================
185+
React.useEffect(() => {
186+
if (searchValue) {
187+
const firstMatchNode = getFirstMatchNode(memoTreeData);
188+
setActiveKey(firstMatchNode ? firstMatchNode[fieldNames.value] : null);
189+
return;
190+
}
191+
192+
if (open) {
193+
if (!multiple && checkedKeys.length) {
194+
setActiveKey(checkedKeys[0]);
195+
} else {
196+
const firstSelectableNode = getFirstSelectableNode(memoTreeData);
197+
if (firstSelectableNode) {
198+
setActiveKey(firstSelectableNode[fieldNames.value]);
199+
}
200+
}
201+
return;
202+
}
203+
setActiveKey(null);
204+
}, [open, searchValue]);
205+
206206
// ========================= Keyboard =========================
207207
React.useImperativeHandle(ref, () => ({
208208
scrollTo: treeRef.current?.scrollTo,

0 commit comments

Comments
 (0)