Skip to content

Commit cf45552

Browse files
authored
fix(ui5-color-picker): enable hex value input change on enter (#4621)
Fixes: #4541
1 parent c384736 commit cf45552

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

packages/main/src/ColorPicker.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<ui5-input
4747
class="ui5-color-picker-hex-input"
4848
value="{{hex}}"
49+
@keydown="{{_onkeydown}}"
4950
@ui5-change="{{_handleHEXChange}}"
5051
value-state="{{hexInputErrorState}}"
5152
></ui5-input>

packages/main/src/ColorPicker.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2+
import { isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
23
import CSSColor from "@ui5/webcomponents-base/dist/types/CSSColor.js";
34
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
45
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
@@ -359,6 +360,10 @@ class ColorPicker extends UI5Element {
359360
newValue = `${newValue[0]}${newValue[0]}${newValue[1]}${newValue[1]}${newValue[2]}${newValue[2]}`;
360361
}
361362

363+
if (newValue === this.hex) {
364+
return;
365+
}
366+
362367
this.hex = newValue;
363368
if (newValue.length !== 6 || !hexRegex.test(newValue)) {
364369
this._wrongHEX = true;
@@ -450,6 +455,12 @@ class ColorPicker extends UI5Element {
450455
}
451456
}
452457

458+
_onkeydown(event) {
459+
if (isEnter(event)) {
460+
this._handleHEXChange(event);
461+
}
462+
}
463+
453464
_calculateColorFromCoordinates(x, y) {
454465
// By using the selected coordinates(x = Lightness, y = Saturation) and hue(selected from the hue slider)
455466
// and HSL format, the color will be parsed to RGB

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ describe("Color Picker general interaction", () => {
102102
assert.strictEqual(await hexInput.getProperty("value"), "808080", "CSS values are parsed correctly");
103103
});
104104

105+
it("Hex value input submit triggers hue value change", async () => {
106+
const colorPicker = await browser.$("#change-event");
107+
const hexInput = await colorPicker.shadow$(".ui5-color-picker-hex-input");
108+
const hueSliderHandle = await colorPicker.shadow$(".ui5-color-picker-hue-slider").shadow$(".ui5-slider-handle");
109+
110+
await hexInput.doubleClick();
111+
await browser.keys("0854a0");
112+
await browser.keys("Enter");
113+
114+
const color = await colorPicker.getAttribute("color");
115+
116+
await hueSliderHandle.dragAndDrop({ x: 200, y: 0 });
117+
118+
await hexInput.doubleClick();
119+
await browser.keys("0854a0");
120+
await browser.keys("Enter");
121+
122+
assert.strictEqual(await colorPicker.getAttribute("color"), color, "Color is changed to the old color");
123+
});
124+
105125
it("Hue value remains unchanged when user presses over the main color section", async () => {
106126
const colorPicker = await browser.$("#change-event");
107127
const hexInput = await colorPicker.shadow$(".ui5-color-picker-hex-input");

0 commit comments

Comments
 (0)