diff --git a/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.ts b/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.ts index 5bc259f9b9..a1d22c70ab 100644 --- a/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.ts +++ b/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.ts @@ -2,15 +2,13 @@ import { Component } from "@odoo/owl"; import { GRID_ICON_EDGE_LENGTH } from "../../../constants"; import { CellPosition, SpreadsheetChildEnv } from "../../../types"; import { css } from "../../helpers"; +import { CHECKBOX_WIDTH, Checkbox } from "../../side_panel/components/checkbox/checkbox"; -const CHECKBOX_WIDTH = 15; const MARGIN = (GRID_ICON_EDGE_LENGTH - CHECKBOX_WIDTH) / 2; css/* scss */ ` .o-dv-checkbox { box-sizing: border-box !important; - width: ${CHECKBOX_WIDTH}px; - height: ${CHECKBOX_WIDTH}px; accent-color: #808080; margin: ${MARGIN}px; /** required to prevent the checkbox position to be sensible to the font-size (affects Firefox) */ @@ -24,14 +22,16 @@ interface Props { export class DataValidationCheckbox extends Component { static template = "o-spreadsheet-DataValidationCheckbox"; + static components = { + Checkbox, + }; static props = { cellPosition: Object, }; - onCheckboxChange(ev: Event) { - const newValue = (ev.target as HTMLInputElement).checked; + onCheckboxChange(value: boolean) { const { sheetId, col, row } = this.props.cellPosition; - const cellContent = newValue ? "TRUE" : "FALSE"; + const cellContent = value ? "TRUE" : "FALSE"; this.env.model.dispatch("UPDATE_CELL", { sheetId, col, row, content: cellContent }); } diff --git a/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.xml b/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.xml index 2bf6c4d92e..f8c3ab203a 100644 --- a/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.xml +++ b/src/components/data_validation_overlay/dv_checkbox/dv_checkbox.xml @@ -1,11 +1,10 @@ - diff --git a/src/components/side_panel/components/checkbox/checkbox.ts b/src/components/side_panel/components/checkbox/checkbox.ts index 782b20b3d4..4dc68127ee 100644 --- a/src/components/side_panel/components/checkbox/checkbox.ts +++ b/src/components/side_panel/components/checkbox/checkbox.ts @@ -19,6 +19,8 @@ interface Props { onChange: (value: boolean) => void; } +export const CHECKBOX_WIDTH = 14; + css/* scss */ ` label.o-checkbox { input { @@ -26,8 +28,8 @@ css/* scss */ ` -webkit-appearance: none; -moz-appearance: none; border-radius: 0; - width: 14px; - height: 14px; + width: ${CHECKBOX_WIDTH}px; + height: ${CHECKBOX_WIDTH}px; vertical-align: top; box-sizing: border-box; outline: none; diff --git a/tests/data_validation/data_validation_checkbox_component.test.ts b/tests/data_validation/data_validation_checkbox_component.test.ts index d100b104b6..40fdd24b6f 100644 --- a/tests/data_validation/data_validation_checkbox_component.test.ts +++ b/tests/data_validation/data_validation_checkbox_component.test.ts @@ -5,7 +5,8 @@ import { setCellContent, setStyle, } from "../test_helpers/commands_helpers"; -import { getStyle } from "../test_helpers/getters_helpers"; +import { click } from "../test_helpers/dom_helper"; +import { getCellContent, getStyle } from "../test_helpers/getters_helpers"; import { mountSpreadsheet, nextTick } from "../test_helpers/helpers"; describe("Checkbox in model", () => { @@ -35,6 +36,21 @@ describe("Checkbox in model", () => { }); describe("Checkbox component", () => { + test("can check and uncheck", async () => { + const model = new Model(); + addDataValidation(model, "A1", "id", { type: "isBoolean", values: [] }); + const { fixture } = await mountSpreadsheet({ model }); + await nextTick(); + const checkbox = fixture.querySelector(".o-dv-checkbox input") as HTMLInputElement; + expect(checkbox?.checked).toBe(false); + await click(checkbox); + expect(getCellContent(model, "A1")).toBe("TRUE"); + expect(checkbox?.checked).toBe(true); + await click(checkbox); + expect(getCellContent(model, "A1")).toBe("FALSE"); + expect(checkbox?.checked).toBe(false); + }); + test("Data validation checkbox on formula is disabled", async () => { const model = new Model(); addDataValidation(model, "A1", "id", { type: "isBoolean", values: [] });