Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes number conversion for dirty input #878

Merged
merged 3 commits into from
Feb 7, 2024
Merged
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
19 changes: 19 additions & 0 deletions cypress/e2e/layers.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
9 changes: 6 additions & 3 deletions src/components/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputNumberProps, InputNumberState> {
Expand Down Expand Up @@ -66,7 +69,7 @@ export default class InputNumber extends React.Component<InputNumberProps, Input
}

this.setState({
dirtyValue: newValue === "" ? undefined : value,
dirtyValue: newValue === "" ? undefined : newValue,
})
}

Expand Down Expand Up @@ -125,7 +128,7 @@ export default class InputNumber extends React.Component<InputNumberProps, Input
// for example we might go from 13 to 13.23, however because we know
// that came from a keyboard event we always want to increase by a
// single step value.
if (value < this.state.dirtyValue!) {
if (value < +this.state.dirtyValue!) {
value = this.state.value! - step;
}
else {
Expand Down
1 change: 1 addition & 0 deletions src/components/InputSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class SpecField extends React.Component<SpecFieldProps> {
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'],
}
Expand Down
Loading