Skip to content

Commit fc61c8b

Browse files
authored
Merge pull request #591 from bjarnef/bug/color-picker-disabled
2 parents 0b6581a + 1e47834 commit fc61c8b

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
107107
margin-left: 0.75rem;
108108
border-radius: 50%;
109109
}
110-
color-picker__trigger {
111-
cursor: pointer;
110+
.color-picker__trigger[disabled] {
111+
cursor: not-allowed;
112+
opacity: 0.5;
112113
}
113114
.color-picker__preview::before,
114115
.color-picker__trigger::before {
@@ -558,14 +559,18 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
558559
'color-picker--disabled': this.disabled,
559560
})}
560561
aria-disabled=${this.disabled ? 'true' : 'false'}>
561-
<uui-color-area .value="${this.value}" @change=${this.handleGridChange}>
562+
<uui-color-area
563+
.value="${this.value}"
564+
?disabled=${this.disabled}
565+
@change=${this.handleGridChange}>
562566
</uui-color-area>
563567
<div class="color-picker__controls">
564568
<div class="color-picker__sliders">
565569
<uui-color-slider
566570
label="hue"
567571
class="hue-slider"
568572
.value=${Math.round(this.hue)}
573+
?disabled=${this.disabled}
569574
@change=${this.handleHueChange}>
570575
</uui-color-slider>
571576
${this.opacity
@@ -576,6 +581,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
576581
.value=${Math.round(this.alpha)}
577582
type="opacity"
578583
.color=${this.value}
584+
?disabled=${this.disabled}
579585
@change=${this.handleAlphaChange}>
580586
</uui-color-slider>
581587
`
@@ -610,21 +616,21 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
610616
</uui-input>
611617
<uui-button-group>
612618
${!this.noFormatToggle
613-
? html`
614-
<uui-button
619+
? html`<uui-button
615620
label="Toggle color format"
616621
@click=${this.handleFormatToggle}
617622
class="color-picker__toggle-format"
623+
?disabled=${this.disabled}
618624
compact>
619625
<span>${this.format}</span>
620-
</uui-button>
621-
`
626+
</uui-button>`
622627
: ''}
623628
${hasEyeDropper
624-
? html` <uui-button
629+
? html`<uui-button
625630
label="Select a color"
626-
compact
627-
@click=${this.handleEyeDropper}>
631+
?disabled=${this.disabled}
632+
@click=${this.handleEyeDropper}
633+
compact>
628634
<uui-icon-registry-essential>
629635
<uui-icon name="colorpicker"></uui-icon>
630636
</uui-icon-registry-essential>
@@ -642,12 +648,14 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
642648
return html`<uui-color-swatches
643649
id="swatches"
644650
class="color-picker__swatches"
651+
?disabled=${this.disabled}
645652
@change=${this.handleColorSwatchChange}>
646653
${this.swatches.map(
647654
swatch =>
648655
html`<uui-color-swatch
649656
label="${swatch}"
650-
.value=${swatch}></uui-color-swatch>`
657+
.value=${swatch}>
658+
</uui-color-swatch>`
651659
)}
652660
</uui-color-swatches>`;
653661
}
@@ -670,6 +678,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
670678
this.lightness
671679
}%, ${this.alpha / 100})`,
672680
})}
681+
?disabled=${this.disabled}
673682
@click=${this.openColorPicker}
674683
aria-haspopup="true"
675684
aria-expanded="false"></button>

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ export const Inline: Story = {
6767
parameters: {
6868
docs: {
6969
source: {
70-
code: `<uui-color-picker inline="true"></uui-color-picker>`,
70+
code: `<uui-color-picker inline></uui-color-picker>`,
71+
},
72+
},
73+
},
74+
};
75+
76+
export const Disabled: Story = {
77+
args: {
78+
disabled: true,
79+
inline: true,
80+
opacity: true,
81+
},
82+
parameters: {
83+
docs: {
84+
source: {
85+
code: `<uui-color-picker inline disabled opacity></uui-color-picker>`,
7186
},
7287
},
7388
},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ export class UUIColorSwatchElement extends LabelMixin(
6262
6363
:host([disabled]) {
6464
cursor: not-allowed;
65+
opacity: 0.5;
6566
}
6667
6768
#swatch {
69+
cursor: inherit;
6870
outline: none;
6971
background: none;
7072
border: none;

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
3535
@property()
3636
value = '';
3737

38+
/**
39+
* Disables the color swatches.
40+
* @type {boolean}
41+
* @attr
42+
* @default false
43+
**/
44+
@property({ type: Boolean, reflect: true }) disabled = false;
45+
3846
@queryAssignedElements({ selector: 'uui-color-swatch' })
3947
swatches!: Array<UUIColorSwatchElement>;
4048

@@ -78,12 +86,17 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
7886
private _handleSlotChange() {
7987
if (!this.swatches || this.swatches.length === 0) return;
8088
this.swatches.forEach(swatch => {
81-
//? does it make sense to have non selectable swatches in the swatches element?
82-
//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:
83-
swatch.setAttribute('selectable', 'selectable');
8489
swatch.setAttribute('aria-checked', 'false');
8590
swatch.setAttribute('role', 'radio');
8691

92+
if (this.disabled) {
93+
swatch.setAttribute('disabled', '')
94+
}
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+
}
99+
87100
if (this.value !== '' && swatch.color?.isEqual(this.value)) {
88101
swatch.selected = true;
89102
swatch.setAttribute('aria-checked', 'true');
@@ -128,6 +141,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
128141
);
129142
}
130143
};
144+
131145
/**
132146
* Deselects all swatches.
133147
*
@@ -137,7 +151,7 @@ export class UUIColorSwatchesElement extends LabelMixin('label', LitElement) {
137151
this.swatches.forEach(swatch => {
138152
swatch.selected = false;
139153
swatch.active = false;
140-
swatch.selectable = true;
154+
swatch.selectable = !swatch.disabled;
141155
});
142156
this._activeElement = undefined;
143157
this._selectedElement = undefined;

0 commit comments

Comments
 (0)