mirror of
https://github.com/maputnik/editor.git
synced 2026-01-06 21:40:01 +00:00
Removes number conversion for dirty input (#878)
Fixes #870 - #870 This regression bug was introduced as part of the refactoring of typescript. Here: - #848 I've added tests to cover the scenario so that it won't happen again, hopefully.
This commit is contained in:
@@ -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", () => {
|
describe("filter", () => {
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ type InputNumberState = {
|
|||||||
editing: boolean
|
editing: boolean
|
||||||
editingRange?: boolean
|
editingRange?: boolean
|
||||||
value?: number
|
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> {
|
export default class InputNumber extends React.Component<InputNumberProps, InputNumberState> {
|
||||||
@@ -66,7 +69,7 @@ export default class InputNumber extends React.Component<InputNumberProps, Input
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
dirtyValue: newValue === "" ? undefined : value,
|
dirtyValue: newValue === "" ? undefined : newValue,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
// 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
|
// that came from a keyboard event we always want to increase by a
|
||||||
// single step value.
|
// single step value.
|
||||||
if (value < this.state.dirtyValue!) {
|
if (value < +this.state.dirtyValue!) {
|
||||||
value = this.state.value! - step;
|
value = this.state.value! - step;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export default class SpecField extends React.Component<SpecFieldProps> {
|
|||||||
value: this.props.value,
|
value: this.props.value,
|
||||||
default: this.props.fieldSpec?.default,
|
default: this.props.fieldSpec?.default,
|
||||||
name: this.props.fieldName,
|
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),
|
onChange: (newValue: number | undefined | (string | number | undefined)[]) => this.props.onChange!(this.props.fieldName, newValue),
|
||||||
'aria-label': this.props['aria-label'],
|
'aria-label': this.props['aria-label'],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user