Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/color_picker/color_picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class ColorPicker extends Component<ColorPickerProps, SpreadsheetChildEnv

setHexColor(ev: InputEvent) {
// only support HEX code input
const val = (ev.target as HTMLInputElement).value.slice(0, 7);
const val = (ev.target as HTMLInputElement).value.replace("##", "#").slice(0, 7);
this.state.customHexColor = val;
if (!isColorValid(val)) {
} else {
Expand Down
1 change: 0 additions & 1 deletion src/components/color_picker/color_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
t-on-click.stop=""
t-att-value="state.customHexColor"
t-on-input="setHexColor"
maxlength="7"
/>
<div class="o-color-preview" t-att-style="colorPreviewStyle"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ exports[`Color Picker buttons Full component rendering 1`] = `
class="o-custom-input-preview"
>
<input
maxlength="7"
type="text"
/>
<div
Expand Down
9 changes: 8 additions & 1 deletion tests/colors/color_picker_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,27 @@ describe("Color Picker buttons", () => {

test.each([
"#fff",
"##fff",
"fff",
"#ffffff",
"##ffffff",
"ffffff",
"#FFFFFF00", // Hex + alpha
])("Can input a custom HEX code, alpha is ignored", async (hexCode) => {
await mountColorPicker();
await simulateClick(".o-color-picker-toggler");

const inputTarget = fixture.querySelector(".o-custom-input-preview input")!;
await setInputValueAndTrigger(inputTarget, hexCode as Color);
expect((inputTarget as HTMLInputElement).value).toBeSameColorAs(hexCode.slice(0, 7));
expect((inputTarget as HTMLInputElement).value).toBeSameColorAs(
hexCode.replace("##", "#").slice(0, 7)
);
const addButton = fixture.querySelector(".o-add-button")!;
expect(addButton.classList).not.toContain("o-disabled");
});

test.each([
"#fff#000",
"rgb(1,1,1)", // rgb
"rgb(1,1,1,0.5)", // rgba
])("refuse non strictly HEX codes", async (hexCode) => {
Expand Down