Skip to content

Commit ea60f3a

Browse files
authored
fix(ui5-color-picker): sanitize input by removing '#' from hex value (#12185)
With this change, it is now possible to use a HEX value that contains "#" within it. The "#" symbol is removed from the value in the input field and does not cause an error. This ensures better compatibility and prevents potential issues when entering HEX codes. fixes: #11417
1 parent 554c1fe commit ea60f3a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/main/cypress/specs/ColorPicker.cy.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ describe("Color Picker general interaction tests", () => {
6565
.ui5ColorPickerValidateInput(".ui5-color-picker-hex-input", "fafafa");
6666
});
6767

68+
it("should correctly sanitize and parse HEX value to color", () => {
69+
cy.mount(<ColorPicker></ColorPicker>);
70+
71+
cy.get("[ui5-color-picker]")
72+
.as("colorPicker");
73+
74+
cy.get<ColorPicker>("@colorPicker")
75+
.ui5ColorPickerUpdateInput(".ui5-color-picker-hex-input", "#fafafa");
76+
77+
cy.get<ColorPicker>("@colorPicker")
78+
.ui5ColorPickerValidateInput(".ui5-color-picker-hex-input", "fafafa");
79+
});
80+
6881
it("should correctly parse short form HEX value to color", () => {
6982
cy.mount(<ColorPicker value="#123"></ColorPicker>);
7083

packages/main/src/ColorPicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ class ColorPicker extends UI5Element implements IFormInputElement {
328328
const input: Input = (e.target as Input);
329329
let inputValueLowerCase = input.value.toLowerCase();
330330

331+
if (inputValueLowerCase.startsWith("#")) {
332+
inputValueLowerCase = inputValueLowerCase.slice(1);
333+
}
334+
331335
// Shorthand Syntax
332336
if (inputValueLowerCase.length === 3) {
333337
inputValueLowerCase = `${inputValueLowerCase[0]}${inputValueLowerCase[0]}${inputValueLowerCase[1]}${inputValueLowerCase[1]}${inputValueLowerCase[2]}${inputValueLowerCase[2]}`;

0 commit comments

Comments
 (0)