Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close select overlay when clicking already selected item #7288

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading