Skip to content

Commit 4b03374

Browse files
authored
fix(ui5-color-picker): adjust hue value update when user presses over the main color section (#4601)
- Hue value remains unchanged when users press over the main color section, in order to change the color. Fixes: #4540
1 parent 29967f0 commit 4b03374

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

packages/main/src/ColorPicker.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ const metadata = {
8787
defaultValue: 0,
8888
},
8989

90+
/**
91+
* @private
92+
*/
93+
_isSelectedColorChanged: {
94+
type: Boolean,
95+
},
96+
97+
/**
98+
* @private
99+
*/
100+
_isHueValueChanged: {
101+
type: Boolean,
102+
},
103+
90104
/**
91105
* @private
92106
*/
@@ -326,6 +340,8 @@ class ColorPicker extends UI5Element {
326340
this.selectedHue = event.target.value;
327341
this._hue = this.selectedHue;
328342
this._setMainColor(this._hue);
343+
// Idication that changes to the hue value triggered as a result of user pressing over the hue slider.
344+
this._isHueValueChanged = true;
329345

330346
const tempColor = this._calculateColorFromCoordinates(this._selectedCoordinates.x + 6.5, this._selectedCoordinates.y + 6.5);
331347

@@ -425,6 +441,9 @@ class ColorPicker extends UI5Element {
425441
y: y - 6.5, // Center the coordinates, because of the height of the circle
426442
};
427443

444+
// Idication that changes to the color settings are triggered as a result of user pressing over the main color section.
445+
this._isSelectedColorChanged = true;
446+
428447
const tempColor = this._calculateColorFromCoordinates(x, y);
429448
if (tempColor) {
430449
this._setColor(HSLToRGB(tempColor));
@@ -435,7 +454,7 @@ class ColorPicker extends UI5Element {
435454
// By using the selected coordinates(x = Lightness, y = Saturation) and hue(selected from the hue slider)
436455
// and HSL format, the color will be parsed to RGB
437456

438-
const h = Math.round(this._hue / 4.25), // 0 ≤ H < 360
457+
const h = this._hue / 4.25, // 0 ≤ H < 360
439458
// 0 ≤ S ≤ 1
440459
s = 1 - +(Math.round((y / 256) + "e+2") + "e-2"), // eslint-disable-line
441460
// 0 ≤ V ≤ 1
@@ -488,7 +507,15 @@ class ColorPicker extends UI5Element {
488507
y: (256 - (Math.round(hslColours.s * 100) * 2.56)) - 6.5, // Center the coordinates, because of the height of the circle
489508
};
490509

491-
this._hue = this.selectedHue ? this.selectedHue : Math.round(hslColours.h * 4.25);
510+
if (this._isSelectedColorChanged) { // We shouldn't update the hue value when user presses over the main color section.
511+
this._isSelectedColorChanged = false;
512+
} else if (this._isHueValueChanged) { // We shouldn't recalculate the hue value when user changes the hue slider.
513+
this._isHueValueChanged = false;
514+
this._hue = this.selectedHue ? this.selectedHue : this._hue;
515+
} else {
516+
this._hue = Math.round(hslColours.h * 4.25);
517+
}
518+
492519
this._setMainColor(this._hue);
493520
}
494521

packages/main/test/specs/ColorPicker.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe("Color Picker general interaction", () => {
7878

7979
await hueSliderHandle.dragAndDrop({ x: 200, y: 0 });
8080

81-
assert.strictEqual(await colorPicker.getAttribute("color"), "rgba(183, 61, 183, 0.83)", "Color properly changed");
81+
assert.strictEqual(await colorPicker.getAttribute("color"), "rgba(183, 61, 182, 0.83)", "Color properly changed");
8282
assert.strictEqual(await stepInput.getAttribute("value"), "2", "Change event gets fired on hue slider change");
8383
});
8484

@@ -102,4 +102,20 @@ describe("Color Picker general interaction", () => {
102102
assert.strictEqual(await hexInput.getProperty("value"), "808080", "CSS values are parsed correctly");
103103
});
104104

105+
it("Hue value remains unchanged when user presses over the main color section", async () => {
106+
const colorPicker = await browser.$("#change-event");
107+
const hexInput = await colorPicker.shadow$(".ui5-color-picker-hex-input");
108+
const mainColorSection = await colorPicker.shadow$(".ui5-color-picker-main-color");
109+
110+
await hexInput.doubleClick();
111+
await browser.keys("0a6ed1");
112+
await browser.keys("Enter");
113+
114+
const hueValue = await colorPicker.getAttribute("_hue");
115+
116+
await mainColorSection.click();
117+
118+
assert.strictEqual(await colorPicker.getAttribute("_hue"), hueValue, "Hue value remained unchanged");
119+
});
120+
105121
});

0 commit comments

Comments
 (0)