Skip to content

Commit

Permalink
fix: restore select focus on fullscreen dropdown close (#3120) (#3121)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomi Virkki <[email protected]>
  • Loading branch information
vaadin-bot and tomivirkki authored Nov 26, 2021
1 parent 3f635b3 commit 3d4680b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dev/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</script>
</head>
<body>
<vaadin-select></vaadin-select>
<vaadin-select label="Size"></vaadin-select>

<script>
const select = document.querySelector('vaadin-select');
Expand Down
10 changes: 3 additions & 7 deletions packages/select/src/vaadin-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,9 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab

this._menuElement.focus();
} else if (wasOpened) {
if (this._phone) {
this._setFocused(false);
} else {
this.focus();
if (this._openedWithFocusRing) {
this.setAttribute('focus-ring', '');
}
this.focus();
if (this._openedWithFocusRing) {
this.setAttribute('focus-ring', '');
}
this.validate();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/select/test/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,19 @@ describe('vaadin-select', () => {
expect(focusedSpy.called).to.be.true;
});

it('should remove focused state on closing the overlay if phone', () => {
it('should restore focused state on closing the overlay if phone', () => {
select._phone = true;
click(select._items[1]);
expect(select.hasAttribute('focused')).to.be.false;
expect(select.hasAttribute('focused')).to.be.true;
});

it('should not focus the button on closing the overlay if phone', () => {
it('should focus the button on closing the overlay if phone', () => {
const focusedSpy = sinon.spy();
select.focusElement.focus = focusedSpy;

select._phone = true;
click(select._items[1]);
expect(focusedSpy.called).to.be.false;
expect(focusedSpy.called).to.be.true;
});

it('should focus the button before moving the focus to next selectable element', () => {
Expand Down

0 comments on commit 3d4680b

Please sign in to comment.