diff --git a/CHANGELOG.md b/CHANGELOG.md index b86d60f7..3250ff36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Keyboard shortcuts now keep working while the map has focus, instead of going dead until the map is blurred - The map no longer stays blank on load until it is moved, when the style loads before the map is ready - The debug modal now shows the MapLibre options for any renderer other than OpenLayers (e.g. `mbgljs`) +- Checkboxes for properties that default to `true` (e.g. `fill-antialias`, `text-keep-upright`) are now shown checked when the property is unset - _...Add new stuff here..._ ## 3.1.0 diff --git a/e2e/layer-editor.spec.ts b/e2e/layer-editor.spec.ts index 8b35ef9d..6f9ffebb 100644 --- a/e2e/layer-editor.spec.ts +++ b/e2e/layer-editor.spec.ts @@ -540,6 +540,17 @@ describe("layer editor", () => { layers: [{ id, type: "fill", source: "example", paint: { "fill-opacity": 0.4 } }], }); }); + + test("antialias is checked when unset, as it defaults to true", async () => { + await then(get.element("[data-wd-key='spec-field:fill-antialias'] input")).shouldBeChecked(); + }); + + test("unchecking antialias sets it to false", async () => { + await when.clickWithin("spec-field:fill-antialias", "input"); + await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ + layers: [{ id, type: "fill", source: "example", paint: { "fill-antialias": false } }], + }); + }); }); describe("json-editor", () => { diff --git a/e2e/playwright-helper.ts b/e2e/playwright-helper.ts index e0d73c8d..8de97774 100644 --- a/e2e/playwright-helper.ts +++ b/e2e/playwright-helper.ts @@ -108,6 +108,7 @@ export class Assertable { shouldBeFocused = () => expect(this.locator().first()).toBeFocused(); shouldNotBeFocused = () => expect(this.locator().first()).not.toBeFocused(); shouldHaveValue = (value: string) => expect(this.locator().first()).toHaveValue(value); + shouldBeChecked = () => expect(this.locator().first()).toBeChecked(); shouldContainText = async (text: string) => { const locator = this.locator(); // Prefer the visible element when a testid resolves to several (only the diff --git a/src/components/InputCheckbox.tsx b/src/components/InputCheckbox.tsx index 31bf5939..fdc388c7 100644 --- a/src/components/InputCheckbox.tsx +++ b/src/components/InputCheckbox.tsx @@ -2,20 +2,22 @@ import React from "react"; export type InputCheckboxProps = { value?: boolean + default?: boolean style?: object onChange(...args: unknown[]): unknown }; export class InputCheckbox extends React.Component { - static defaultProps = { - value: false, - }; + isChecked() { + return this.props.value ?? this.props.default ?? false; + } onChange = () => { - this.props.onChange(!this.props.value); + this.props.onChange(!this.isChecked()); }; render() { + const checked = this.isChecked(); return
{ style={this.props.style} onChange={this.onChange} onClick={this.onChange} - checked={this.props.value} + checked={checked} />