Skip to content

Commit

Permalink
fix selectable mixin so it only selects when the right element is cli…
Browse files Browse the repository at this point in the history
…cked
  • Loading branch information
nielslyngsoe committed Nov 20, 2024
1 parent 8f781ce commit c5bf804
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/uui-base/lib/mixins/SelectableMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
}

private _handleClick(e: Event) {
if (e.composedPath().indexOf(this.selectableTarget) !== -1) {
const composePath = e.composedPath();
if (
(this._selectable || (this.deselectable && this.selected)) &&
composePath.indexOf(this.selectableTarget) === 0
) {
this._toggleSelect();
}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/uui-card-media/lib/uui-card-media.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ describe('UUICardMediaElement', () => {
expect(event.type).to.equal(UUISelectableEvent.SELECTED);
expect(element.selected).to.be.true;
});
it('do react to a click event on performed in this way', async () => {
element.selectable = true;
await elementUpdated(element);
element.click();
await Promise.resolve();
expect(element.selected).to.be.true;
});
it('do not react to a click event on other parts', async () => {
element.selectable = true;
await elementUpdated(element);
element
.shadowRoot!.querySelector<HTMLAnchorElement>('#open-part')!
.click();
await Promise.resolve();
expect(element.selected).to.be.false;
});
it('can be selected with keyboard', async () => {
element.selectable = true;
await elementUpdated(element);
Expand Down

0 comments on commit c5bf804

Please sign in to comment.