Skip to content

Commit cc7eb33

Browse files
authored
fix: remove focus trap when overlay mode is reset to false (#9514)
1 parent f56c531 commit cc7eb33

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/app-layout/src/vaadin-app-layout-mixin.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const AppLayoutMixin = (superclass) =>
6969
readOnly: true,
7070
value: false,
7171
reflectToAttribute: true,
72+
observer: '__overlayChanged',
7273
sync: true,
7374
},
7475

@@ -247,6 +248,22 @@ export const AppLayoutMixin = (superclass) =>
247248
this.__setAriaExpanded();
248249
}
249250

251+
/**
252+
* A callback for the `overlay` property observer.
253+
*
254+
* When layout resizes while in the overlay mode, drawer opened state
255+
* is not changed, but focus trap needs to be removed.
256+
*
257+
* @param {boolean} overlay
258+
* @param {boolean} oldOverlay
259+
* @private
260+
*/
261+
__overlayChanged(_overlay, oldOverlay) {
262+
if (oldOverlay) {
263+
this.__restoreFocus();
264+
}
265+
}
266+
250267
/**
251268
* A callback for the `i18n` property observer.
252269
*
@@ -409,9 +426,7 @@ export const AppLayoutMixin = (superclass) =>
409426
return;
410427
}
411428

412-
this.__ariaModalController.close();
413-
this.__focusTrapController.releaseFocus();
414-
this.$.drawer.removeAttribute('tabindex');
429+
this.__restoreFocus();
415430

416431
// Move focus to the drawer toggle when closing the drawer.
417432
const toggle = this.querySelector('vaadin-drawer-toggle');
@@ -421,6 +436,13 @@ export const AppLayoutMixin = (superclass) =>
421436
}
422437
}
423438

439+
/** @private */
440+
__restoreFocus() {
441+
this.__ariaModalController.close();
442+
this.__focusTrapController.releaseFocus();
443+
this.$.drawer.removeAttribute('tabindex');
444+
}
445+
424446
/**
425447
* Closes the drawer on Escape press if it has been opened in the overlay mode.
426448
*

packages/app-layout/test/app-layout.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,17 @@ describe('vaadin-app-layout', () => {
458458
await nextFrame();
459459
expect(spy.called).to.be.false;
460460
});
461+
462+
it('should remove drawer tabindex when it resizes from the overlay mode', async () => {
463+
expect(drawer.hasAttribute('tabindex')).to.be.true;
464+
465+
// Force it to desktop layout
466+
layout.style.setProperty('--vaadin-app-layout-drawer-overlay', 'false');
467+
layout._updateOverlayMode();
468+
await nextRender();
469+
470+
expect(drawer.hasAttribute('tabindex')).to.be.false;
471+
});
461472
});
462473
});
463474
});

0 commit comments

Comments
 (0)