Skip to content

Commit 229f4f7

Browse files
committed
chore: remove unnecessary logic
1 parent 4640c4d commit 229f4f7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/OptionList.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,27 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
179179
if (!open) {
180180
return;
181181
}
182+
let nextActiveKey = null;
182183

183-
// // Prioritize activating the searched node
184-
if (searchValue) {
184+
const getFirstNode = () => {
185185
const firstNode = getFirstMatchingNode(memoTreeData);
186-
setActiveKey(firstNode ? firstNode[fieldNames.value] : null);
187-
return;
188-
}
186+
return firstNode ? firstNode[fieldNames.value] : null;
187+
};
189188

190-
// If no search value, activate the first checked node
191-
if (!multiple && checkedKeys.length) {
192-
setActiveKey(checkedKeys[0]);
193-
return;
189+
// search mode active first node
190+
if (searchValue) {
191+
nextActiveKey = getFirstNode();
192+
}
193+
// single mode active first checked node
194+
else if (!multiple && checkedKeys.length) {
195+
nextActiveKey = checkedKeys[0];
196+
}
197+
// default active first node
198+
else {
199+
nextActiveKey = getFirstNode();
194200
}
195201

196-
// If no search value and no checked nodes, activate the first node
197-
const firstNode = getFirstMatchingNode(memoTreeData);
198-
setActiveKey(firstNode ? firstNode[fieldNames.value] : null);
202+
setActiveKey(nextActiveKey);
199203
}, [open, searchValue]);
200204

201205
// ========================= Keyboard =========================

0 commit comments

Comments
 (0)