diff --git a/cypress/e2e/layers.cy.ts b/cypress/e2e/layers.cy.ts index d59f9eed..4be2949f 100644 --- a/cypress/e2e/layers.cy.ts +++ b/cypress/e2e/layers.cy.ts @@ -280,6 +280,25 @@ describe("layers", () => { }); }); }); + + describe("opacity", () => { + let bgId: string; + beforeEach(() => { + bgId = createBackground(); + when.click("layer-list-item:background:" + bgId); + when.type("spec-field-input:background-opacity", "0."); + }); + + it("should keep '.' in the input field", () => { + then(get.elementByTestId("spec-field-input:background-opacity")).shouldHaveValue("0."); + }); + + it("should revert to a valid value when focus out", () => { + when.click("layer-list-item:background:" + bgId); + then(get.elementByTestId("spec-field-input:background-opacity")).shouldHaveValue('0'); + }); + }); + }); describe("filter", () => { diff --git a/src/components/InputNumber.tsx b/src/components/InputNumber.tsx index 24ce52d1..64f2e139 100644 --- a/src/components/InputNumber.tsx +++ b/src/components/InputNumber.tsx @@ -19,7 +19,10 @@ type InputNumberState = { editing: boolean editingRange?: boolean value?: number - dirtyValue?: number + /** + * This is the value that is currently being edited. It can be an invalid value. + */ + dirtyValue?: number | string | undefined } export default class InputNumber extends React.Component { @@ -66,7 +69,7 @@ export default class InputNumber extends React.Component { value: this.props.value, default: this.props.fieldSpec?.default, name: this.props.fieldName, + "data-wd-key": "spec-field-input:" + this.props.fieldName, onChange: (newValue: number | undefined | (string | number | undefined)[]) => this.props.onChange!(this.props.fieldName, newValue), 'aria-label': this.props['aria-label'], }