Skip to content

Commit 258b0c5

Browse files
committed
only care about the composedPath when selectableTarget is this.
1 parent a7d67a9 commit 258b0c5

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/uui-base/lib/mixins/SelectableMixin.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
9494
};
9595

9696
readonly #onClick = (e: Event) => {
97-
const composePath = e.composedPath();
98-
if (
99-
(this._selectable || (this.deselectable && this.selected)) &&
100-
composePath.indexOf(this.selectableTarget) === 0
101-
) {
97+
const isSelectable =
98+
this._selectable || (this.deselectable && this.selected);
99+
100+
if (isSelectable === false) return;
101+
102+
if (this.selectableTarget === this) {
103+
// If target is this, then only allow selection if the click is on the element itself.
104+
if (e.composedPath().indexOf(this.selectableTarget) === 0) {
105+
this.#toggleSelect();
106+
}
107+
} else {
102108
this.#toggleSelect();
103109
}
104110
};

packages/uui-color-swatch/lib/uui-color-swatch.element.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
22
import { property } from 'lit/decorators.js';
33
import { css, html, LitElement, nothing } from 'lit';
4+
import { ref } from 'lit/directives/ref.js';
45
import { iconCheck } from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
56
import {
67
ActiveMixin,
@@ -109,10 +110,15 @@ export class UUIColorSwatchElement extends LabelMixin(
109110
}
110111
}
111112

113+
#selectButtonChanged(button?: Element | undefined) {
114+
this.selectableTarget = button || this;
115+
}
116+
112117
render() {
113118
return html`
114119
<button
115120
id="swatch"
121+
${ref(this.#selectButtonChanged)}
116122
aria-label=${this.label}
117123
?disabled="${this.disabled}"
118124
title="${this.label}">

0 commit comments

Comments
 (0)