Skip to content

Commit 27b456e

Browse files
author
叶文俊
committed
fix: focus the first selected item if an item is already selected
1 parent 935b711 commit 27b456e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Menu.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,16 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
398398
? element2key.get(focusableElements[0])
399399
: childList.find(node => !node.props.disabled)?.key;
400400
let shouldFocusKey: string;
401-
// find the item to focus on based on whether it is selectable.
401+
// find the item to focus on based on whether it is selectable
402402
if (selectable) {
403-
// if there is already a selected item, do not apply the focus.
404-
if (!getMergedSelectKeys()?.length) {
405-
if (mergedActiveKey && keys.includes(mergedActiveKey)) {
406-
shouldFocusKey = mergedActiveKey;
407-
} else {
408-
shouldFocusKey = defaultFocusKey;
409-
}
403+
const mergedSelectKeys = getMergedSelectKeys();
404+
// if there is already selected items, select first item to focus
405+
if (mergedSelectKeys.length && keys.includes(mergedSelectKeys[0])) {
406+
shouldFocusKey = mergedSelectKeys[0];
407+
} else if (mergedActiveKey && keys.includes(mergedActiveKey)) {
408+
shouldFocusKey = mergedActiveKey;
409+
} else {
410+
shouldFocusKey = defaultFocusKey;
410411
}
411412
} else {
412413
shouldFocusKey = defaultFocusKey;

0 commit comments

Comments
 (0)