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: detect item correctly when clicking item content (#7371) (CP: 24.3) #7373

Merged
merged 1 commit into from
May 3, 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
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
Loading