Skip to content

Commit dc445f3

Browse files
Welander1994nielslyngsoeiOvergaard
authored
fix(uui-color-picker): alpha should default to 100 if there is no color string (#1061)
* add new check on alpha to check if undefined * cleanup removing console.logs * revert change with check on opacity * fix: set 'alpha' to default to 100 (visible) if there is no color selected as this improves the UX --------- Co-authored-by: Niels Lyngsø <[email protected]> Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 5a14b6a commit dc445f3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
7474
@state() private hue = 0;
7575
@state() private saturation = 0;
7676
@state() private lightness = 0;
77-
@state() private alpha = 0;
77+
@state() private alpha = 100;
7878
@state() private _colord: Colord = colord('hsl(0, 0%, 0%)');
7979

8080
/**
@@ -361,7 +361,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
361361
if (colorString === this.value) return;
362362

363363
if (!colorString) {
364-
this.alpha = 0;
364+
this.alpha = 100;
365365
this.inputValue = '';
366366
this._value = colorString;
367367

@@ -379,7 +379,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
379379
this.hue = h;
380380
this.saturation = s;
381381
this.lightness = l;
382-
this.alpha = this.opacity ? a * 100 : 100;
382+
this.alpha = this.opacity ? a * 100 : 100; // Convert to 0-100 range, and set alpha to 100 if opacity is disabled
383383

384384
const hslaColor = colorString as HslaColor;
385385

@@ -395,7 +395,6 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
395395
this.dispatchEvent(
396396
new UUIColorPickerChangeEvent(UUIColorPickerChangeEvent.CHANGE),
397397
);
398-
399398
return true;
400399
}
401400

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const Inline: Story = {
7373
export const Opacity: Story = {
7474
args: {
7575
opacity: true,
76+
value: undefined,
7677
inline: true,
7778
},
7879
};

0 commit comments

Comments
 (0)