Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ade038c

Browse files
Yavanostacopybara-github
authored andcommitted
fix(MenuSurface): fix focus restoration on nested menu surfaces
PiperOrigin-RevId: 466109850
1 parent b20d3d7 commit ade038c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/mdc-menu-surface/foundation.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -636,21 +636,21 @@ export class MDCMenuSurfaceFoundation extends
636636
* closed.
637637
*/
638638
private maybeRestoreFocus() {
639-
const isRootFocused = this.adapter.isFocused();
640-
const ownerDocument = this.adapter.getOwnerDocument ?
641-
this.adapter.getOwnerDocument() :
642-
document;
643-
const childHasFocus = ownerDocument.activeElement &&
644-
this.adapter.isElementInContainer(ownerDocument.activeElement);
645-
if (isRootFocused || childHasFocus) {
646-
// Wait before restoring focus when closing the menu surface. This is
647-
// important because if a touch event triggered the menu close, and the
648-
// subsequent mouse event occurs after focus is restored, then the
649-
// restored focus would be lost.
650-
setTimeout(() => {
639+
// Wait before restoring focus when closing the menu surface. This is
640+
// important because if a touch event triggered the menu close, and the
641+
// subsequent mouse event occurs after focus is restored, then the
642+
// restored focus would be lost.
643+
setTimeout(() => {
644+
const isRootFocused = this.adapter.isFocused();
645+
const ownerDocument = this.adapter.getOwnerDocument ?
646+
this.adapter.getOwnerDocument() :
647+
document;
648+
const childHasFocus = ownerDocument.activeElement &&
649+
this.adapter.isElementInContainer(ownerDocument.activeElement);
650+
if (isRootFocused || childHasFocus) {
651651
this.adapter.restoreFocus();
652-
}, numbers.TOUCH_EVENT_WAIT_MS);
653-
}
652+
}
653+
}, numbers.TOUCH_EVENT_WAIT_MS);
654654
}
655655

656656
private hasBit(corner: Corner, bit: CornerBit): boolean {

0 commit comments

Comments
 (0)