Skip to content

Commit

Permalink
fix: close select overlay when clicking already selected item (#7288) (
Browse files Browse the repository at this point in the history
…#7290)

Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Mar 28, 2024
1 parent 2993bcc commit a7f23ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ export const SelectBaseMixin = (superClass) =>
menuElement.addEventListener('keydown', (e) => this._onKeyDownInside(e), true);
menuElement.addEventListener(
'click',
() => {
this.__dispatchChangePending = true;
(e) => {
const value = e.target.value;
this.__dispatchChangePending = value !== undefined && value !== this.value;
this.opened = false;
},
true,
);
Expand Down Expand Up @@ -523,7 +525,6 @@ export const SelectBaseMixin = (superClass) =>
this._selectedChanging = true;
this.value = selected.value || '';
if (this.__dispatchChangePending) {
this.opened = false;
this.__dispatchChange();
}
delete this._selectedChanging;
Expand Down
12 changes: 12 additions & 0 deletions packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ describe('vaadin-select', () => {
expect(select._overlayElement.opened).to.be.false;
});

it('should close the overlay when clicking an already selected item', async () => {
click(select._items[1]);
await nextUpdate(select);

select.opened = true;
await nextRender();

click(select._items[1]);
await nextUpdate(select);
expect(select._overlayElement.opened).to.be.false;
});

it('should preserve the selected attribute when selecting the disabled item', async () => {
menu.selected = 5;
await nextUpdate(select);
Expand Down

0 comments on commit a7f23ac

Please sign in to comment.