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

fix(MenuSurface): fix focus restoration on nested menu surfaces #7692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/mdc-menu-surface/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,21 +636,21 @@ export class MDCMenuSurfaceFoundation extends
* closed.
*/
private maybeRestoreFocus() {
const isRootFocused = this.adapter.isFocused();
const ownerDocument = this.adapter.getOwnerDocument ?
this.adapter.getOwnerDocument() :
document;
const childHasFocus = ownerDocument.activeElement &&
this.adapter.isElementInContainer(ownerDocument.activeElement);
if (isRootFocused || childHasFocus) {
// Wait before restoring focus when closing the menu surface. This is
// important because if a touch event triggered the menu close, and the
// subsequent mouse event occurs after focus is restored, then the
// restored focus would be lost.
setTimeout(() => {
// Wait before restoring focus when closing the menu surface. This is
// important because if a touch event triggered the menu close, and the
// subsequent mouse event occurs after focus is restored, then the
// restored focus would be lost.
setTimeout(() => {
const isRootFocused = this.adapter.isFocused();
const ownerDocument = this.adapter.getOwnerDocument ?
this.adapter.getOwnerDocument() :
document;
const childHasFocus = ownerDocument.activeElement &&
this.adapter.isElementInContainer(ownerDocument.activeElement);
if (isRootFocused || childHasFocus) {
this.adapter.restoreFocus();
}, numbers.TOUCH_EVENT_WAIT_MS);
}
}
}, numbers.TOUCH_EVENT_WAIT_MS);
}

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