Skip to content

Commit

Permalink
fix: detect item correctly when clicking item content (#7371)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored May 2, 2024
1 parent 504787f commit 3c32fbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ export const SelectBaseMixin = (superClass) =>
menuElement.addEventListener(
'click',
(e) => {
const value = e.target.value;
this.__dispatchChangePending = value !== undefined && value !== this.value;
const item = e.composedPath().find((el) => el._hasVaadinItemMixin);
this.__dispatchChangePending = Boolean(item && item.value !== undefined && item.value !== this.value);
this.opened = false;
},
true,
Expand Down
11 changes: 10 additions & 1 deletion packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('vaadin-select', () => {
html`
<vaadin-list-box>
<vaadin-item>Option 1</vaadin-item>
<vaadin-item value="v2" label="o2">Option 2</vaadin-item>
<vaadin-item value="v2" label="o2"><span>Option 2</span></vaadin-item>
<vaadin-item value="">Option 3</vaadin-item>
<vaadin-item></vaadin-item>
<vaadin-item label="">Empty</vaadin-item>
Expand Down Expand Up @@ -617,6 +617,15 @@ describe('vaadin-select', () => {
expect(changeSpy.callCount).to.equal(1);
});

it('should fire `change` event when value changes by user clicking the element inside item', async () => {
select.opened = true;
await nextUpdate(select);
const span = menu.children[1].firstElementChild;
span.click();
await nextUpdate(select);
expect(changeSpy).to.be.calledOnce;
});

it('should fire `change` event when value changes by user selecting item with keyboard', async () => {
select.opened = true;
await nextUpdate(select);
Expand Down

0 comments on commit 3c32fbe

Please sign in to comment.