Skip to content

Commit

Permalink
chore: remove unnecessary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aojunhao123 committed Nov 6, 2024
1 parent 4640c4d commit 229f4f7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,27 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
if (!open) {
return;
}
let nextActiveKey = null;

// // Prioritize activating the searched node
if (searchValue) {
const getFirstNode = () => {
const firstNode = getFirstMatchingNode(memoTreeData);
setActiveKey(firstNode ? firstNode[fieldNames.value] : null);
return;
}
return firstNode ? firstNode[fieldNames.value] : null;
};

// If no search value, activate the first checked node
if (!multiple && checkedKeys.length) {
setActiveKey(checkedKeys[0]);
return;
// search mode active first node
if (searchValue) {
nextActiveKey = getFirstNode();
}
// single mode active first checked node
else if (!multiple && checkedKeys.length) {
nextActiveKey = checkedKeys[0];
}
// default active first node
else {
nextActiveKey = getFirstNode();
}

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

// ========================= Keyboard =========================
Expand Down

0 comments on commit 229f4f7

Please sign in to comment.