Skip to content

Commit d01119c

Browse files
authored
refactor: only set focusVisible on closing drawer with keyboard (#10368)
1 parent b514373 commit d01119c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import { AriaModalController } from '@vaadin/a11y-base/src/aria-modal-controller.js';
77
import { FocusTrapController } from '@vaadin/a11y-base/src/focus-trap-controller.js';
8+
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
89
import { animationFrame } from '@vaadin/component-base/src/async.js';
910
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
1011
import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
@@ -443,7 +444,7 @@ export const AppLayoutMixin = (superclass) =>
443444
// Move focus to the drawer toggle when closing the drawer.
444445
const toggle = this.querySelector('vaadin-drawer-toggle');
445446
if (toggle) {
446-
toggle.focus();
447+
toggle.focus({ focusVisible: isKeyboardActive() });
447448
}
448449
}
449450

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
esc,
55
fixtureSync,
66
makeSoloTouchEvent,
7+
mousedown,
78
nextFrame,
89
nextRender,
910
nextResize,
@@ -459,6 +460,21 @@ describe('vaadin-app-layout', () => {
459460
expect(spy.called).to.be.false;
460461
});
461462

463+
it('should focus the drawer toggle with focusVisible: false on closing with mouse', async () => {
464+
const spy = sinon.spy(toggle, 'focus');
465+
mousedown(document.body);
466+
layout.drawerOpened = false;
467+
await nextFrame();
468+
expect(spy.firstCall.args[0]).to.eql({ focusVisible: false });
469+
});
470+
471+
it('should focus the drawer toggle with focusVisible: true on closing with keyboard', async () => {
472+
const spy = sinon.spy(toggle, 'focus');
473+
esc(drawer);
474+
await nextFrame();
475+
expect(spy.firstCall.args[0]).to.eql({ focusVisible: true });
476+
});
477+
462478
it('should remove drawer tabindex when it resizes from the overlay mode', async () => {
463479
expect(drawer.hasAttribute('tabindex')).to.be.true;
464480

0 commit comments

Comments
 (0)