Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit f98f117

Browse files
authored
Fix bug occuring when value exceed bounds in slider input (#114)
[Bug 32632] * soved bug with input and capacitive touch * using shift instead * Fixing input bound issues * restore old version * restoring old version * change value update method * solving send message delay * removing comments * removed duplicated code * clean upaccording to review and cs * removing redundant lines * correcting review suggestion issues
1 parent 0a7ff68 commit f98f117

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/view/components/toolbar/InputSlider.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
6262
onInput={this.handleOnChange}
6363
defaultValue={this.props.minValue.toLocaleString()}
6464
pattern="^-?[0-9]{0,3}$"
65-
onKeyUp={this.validateRange}
65+
onKeyUp={this.handleOnChange}
6666
aria-label={`${this.props.type} sensor input ${this.props.axisLabel}`}
6767
/>
6868
<span className="sliderArea">
@@ -92,36 +92,45 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
9292
);
9393
}
9494

95-
private handleOnChange(event: React.ChangeEvent<HTMLInputElement>) {
96-
this.updateValue(event);
97-
this.validateRange();
98-
const newSensorState = this.writeMessage(event);
95+
private handleOnChange = (event: any) => {
96+
const validatedValue = this.validateRange(this.updateValue(event));
97+
98+
const newSensorState = this.writeMessage(validatedValue);
9999
if (newSensorState) {
100100
sendMessage(newSensorState);
101101
}
102-
}
102+
};
103103

104-
private writeMessage(event: React.ChangeEvent<HTMLInputElement>) {
105-
return this.props.type && this.state.value && event.target.value
106-
? { [this.props.type]: parseInt(event.target.value, 10) }
104+
private writeMessage = (valueTowrite: number) => {
105+
let value = valueTowrite;
106+
if (value > this.props.maxValue || value < this.props.minValue) {
107+
value = parseInt(this.state.value, 10);
108+
}
109+
110+
return this.props.type && this.state.value
111+
? { [this.props.type]: value }
107112
: undefined;
108-
}
113+
};
109114

110-
private updateValue(event: React.ChangeEvent<HTMLInputElement>) {
115+
private updateValue = (event: any) => {
111116
const newValue = event.target.validity.valid
112117
? event.target.value
113118
: this.state.value;
114119
this.setState({ value: newValue });
115-
}
120+
return newValue;
121+
};
116122

117-
private validateRange() {
118-
if (this.state.value < this.props.minValue) {
119-
this.setState({ value: this.props.minValue });
123+
private validateRange = (valueString: string) => {
124+
let valueInt = parseInt(valueString, 10);
125+
if (valueInt < this.props.minValue) {
126+
valueInt = this.props.minValue;
127+
this.setState({ value: valueInt });
128+
} else if (valueInt > this.props.maxValue) {
129+
valueInt = this.props.maxValue;
130+
this.setState({ value: valueInt });
120131
}
121-
if (this.state.value > this.props.maxValue) {
122-
this.setState({ value: this.props.maxValue });
123-
}
124-
}
132+
return valueInt;
133+
};
125134
}
126135

127136
export default InputSlider;

0 commit comments

Comments
 (0)