Skip to content

Commit

Permalink
fix: do not set focus on menu after unmounted (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
szhsin committed Oct 10, 2023
1 parent 0579383 commit 85210a6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dist/es/components/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ const MenuList = ({
setItemFocus();
} else if (captureFocus) {
const id = setTimeout(() => {
if (!menuRef.current.contains(document.activeElement)) {
const menuElt = menuRef.current;
if (menuElt && !menuElt.contains(document.activeElement)) {
focusRef.current.focus();
setItemFocus();
}
Expand Down
2 changes: 1 addition & 1 deletion dist/es/utils/submenuCtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createSubmenuCtx = () => {
pending();
}, closeDelay);
} else {
settled == null ? void 0 : settled();
settled == null || settled();
}
},
off: () => {
Expand Down
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const createSubmenuCtx = () => {
pending();
}, closeDelay);
} else {
settled == null ? void 0 : settled();
settled == null || settled();
}
},
off: () => {
Expand Down Expand Up @@ -1172,7 +1172,8 @@ const MenuList = ({
setItemFocus();
} else if (captureFocus) {
const id = setTimeout(() => {
if (!menuRef.current.contains(document.activeElement)) {
const menuElt = menuRef.current;
if (menuElt && !menuElt.contains(document.activeElement)) {
focusRef.current.focus();
setItemFocus();
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ export const MenuList = ({
const id = setTimeout(
() => {
// If focus has already been set to a children element, don't set focus on menu or item
if (!menuRef.current.contains(document.activeElement)) {
const menuElt = menuRef.current;
if (menuElt && !menuElt.contains(document.activeElement)) {
focusRef.current.focus();
setItemFocus();
}
Expand Down

0 comments on commit 85210a6

Please sign in to comment.