Skip to content

Commit cdadcb5

Browse files
authored
refactor: update select to use overlay focus restoration logic (#7601)
1 parent cf4da7e commit cdadcb5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/select/src/vaadin-select-base-mixin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ export const SelectBaseMixin = (superClass) =>
378378
this.removeAttribute('focus-ring');
379379
}
380380
} else if (wasOpened) {
381-
this.focus();
382381
if (this._openedWithFocusRing) {
383382
this.setAttribute('focus-ring', '');
384383
}

packages/select/src/vaadin-select-overlay-mixin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export const SelectOverlayMixin = (superClass) =>
1919
return ['_updateOverlayWidth(opened, owner)'];
2020
}
2121

22+
/** @protected */
23+
ready() {
24+
super.ready();
25+
26+
this.restoreFocusOnClose = true;
27+
}
28+
2229
/** @protected */
2330
_getMenuElement() {
2431
return Array.from(this.children).find((el) => el.localName !== 'style');

packages/select/test/keyboard.common.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers';
2+
import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick } from '@vaadin/testing-helpers';
33
import { sendKeys } from '@web/test-runner-commands';
44
import sinon from 'sinon';
55

@@ -67,7 +67,7 @@ describe('keyboard', () => {
6767
});
6868
});
6969

70-
it('should focus value button element on overlay closing', async () => {
70+
it('should focus value button element on overlay closing with Esc', async () => {
7171
await sendKeys({ press: 'Tab' });
7272

7373
await sendKeys({ press: 'Enter' });
@@ -81,6 +81,21 @@ describe('keyboard', () => {
8181
expect(focusedSpy.calledOnce).to.be.true;
8282
});
8383

84+
it('should focus value button element on overlay closing with outside click', async () => {
85+
await sendKeys({ press: 'Tab' });
86+
87+
await sendKeys({ press: 'Enter' });
88+
await nextRender();
89+
90+
const focusedSpy = sinon.spy(valueButton, 'focus');
91+
92+
outsideClick();
93+
await nextUpdate(select);
94+
await aTimeout(0);
95+
96+
expect(focusedSpy.calledOnce).to.be.true;
97+
});
98+
8499
it('should restore focus-ring attribute on overlay closing', async () => {
85100
await sendKeys({ press: 'Tab' });
86101

0 commit comments

Comments
 (0)