Skip to content

Commit 826b4b9

Browse files
committed
Make swatches non selectable when disabled
1 parent 9eadb64 commit 826b4b9

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
648648
return html`<uui-color-swatches
649649
id="swatches"
650650
class="color-picker__swatches"
651+
?disabled=${this.disabled}
651652
@change=${this.handleColorSwatchChange}>
652653
${this.swatches.map(
653654
swatch =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class UUIColorSwatchElement extends LabelMixin(
6666
}
6767
6868
#swatch {
69+
cursor: inherit;
6970
outline: none;
7071
background: none;
7172
border: none;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
8686
private _handleSlotChange() {
8787
if (!this.swatches || this.swatches.length === 0) return;
8888
this.swatches.forEach(swatch => {
89-
//? does it make sense to have non selectable swatches in the swatches element?
90-
//for some reason the value it really wants the attribute to be set not the value. If value is set then it is not reflected properly. :cry:
91-
swatch.setAttribute('selectable', 'selectable');
9289
swatch.setAttribute('aria-checked', 'false');
9390
swatch.setAttribute('role', 'radio');
9491

9592
if (this.disabled) {
9693
swatch.setAttribute('disabled', '')
9794
}
95+
else {
96+
// For some reason the value it really wants the attribute to be set not the value. If value is set then it is not reflected properly. :cry:
97+
swatch.setAttribute('selectable', 'selectable');
98+
}
9899

99100
if (this.value !== '' && swatch.color?.isEqual(this.value)) {
100101
swatch.selected = true;
@@ -140,6 +141,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
140141
);
141142
}
142143
};
144+
143145
/**
144146
* Deselects all swatches.
145147
*
@@ -149,7 +151,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
149151
this.swatches.forEach(swatch => {
150152
swatch.selected = false;
151153
swatch.active = false;
152-
swatch.selectable = true;
154+
swatch.selectable = !swatch.disabled;
153155
});
154156
this._activeElement = undefined;
155157
this._selectedElement = undefined;

0 commit comments

Comments
 (0)