Skip to content

Commit 31788df

Browse files
committed
[IMP] color-picker: remove additional #
How to reproduce Copy a color code (i.e. #E6F2F3) Create a custom table Edit its color using the color picker Double-click the current code and replace it by #E6F2F3 As the double-click doesn't grab the #, you get ##E6F2F closes #6104 Task: 4687930 Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
1 parent a8b267f commit 31788df

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/components/color_picker/color_picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class ColorPicker extends Component<ColorPickerProps, SpreadsheetChildEnv
366366

367367
setHexColor(ev: InputEvent) {
368368
// only support HEX code input
369-
const val = (ev.target as HTMLInputElement).value.slice(0, 7);
369+
const val = (ev.target as HTMLInputElement).value.replace("##", "#").slice(0, 7);
370370
this.state.customHexColor = val;
371371
if (!isColorValid(val)) {
372372
} else {

src/components/color_picker/color_picker.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
t-on-click.stop=""
7272
t-att-value="state.customHexColor"
7373
t-on-input="setHexColor"
74-
maxlength="7"
7574
/>
7675
<div class="o-color-preview" t-att-style="colorPreviewStyle"/>
7776
</div>

tests/colors/__snapshots__/color_picker_component.test.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ exports[`Color Picker buttons Full component rendering 1`] = `
500500
class="o-custom-input-preview"
501501
>
502502
<input
503-
maxlength="7"
504503
type="text"
505504
/>
506505
<div

tests/colors/color_picker_component.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,27 @@ describe("Color Picker buttons", () => {
176176

177177
test.each([
178178
"#fff",
179+
"##fff",
179180
"fff",
181+
"#ffffff",
182+
"##ffffff",
183+
"ffffff",
180184
"#FFFFFF00", // Hex + alpha
181185
])("Can input a custom HEX code, alpha is ignored", async (hexCode) => {
182186
await mountColorPicker();
183187
await simulateClick(".o-color-picker-toggler");
184188

185189
const inputTarget = fixture.querySelector(".o-custom-input-preview input")!;
186190
await setInputValueAndTrigger(inputTarget, hexCode as Color);
187-
expect((inputTarget as HTMLInputElement).value).toBeSameColorAs(hexCode.slice(0, 7));
191+
expect((inputTarget as HTMLInputElement).value).toBeSameColorAs(
192+
hexCode.replace("##", "#").slice(0, 7)
193+
);
188194
const addButton = fixture.querySelector(".o-add-button")!;
189195
expect(addButton.classList).not.toContain("o-disabled");
190196
});
191197

192198
test.each([
199+
"#fff#000",
193200
"rgb(1,1,1)", // rgb
194201
"rgb(1,1,1,0.5)", // rgba
195202
])("refuse non strictly HEX codes", async (hexCode) => {

0 commit comments

Comments
 (0)