Skip to content

Commit a3b4673

Browse files
committed
Fix plotly#2612: unexpected behaviour of the cursor
When inserting a non valid character in the middle of a pattern, the cursor instantly jumps to the end of the word, instead of staying in that position.
1 parent c847882 commit a3b4673

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

components/dash-core-components/src/components/Input.react.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,23 @@ export default class Input extends PureComponent {
184184

185185
onChange() {
186186
const {debounce} = this.props;
187-
if (debounce) {
188-
if (Number.isFinite(debounce)) {
189-
this.debounceEvent(debounce);
190-
}
191-
if (this.props.type !== 'number') {
192-
this.setState({value: this.input.current.value});
187+
const input = this.input.current;
188+
const cursorPosition = input.selectionStart;
189+
const currentValue = input.value;
190+
this.setState({value: currentValue}, () => {
191+
if (debounce) {
192+
if (Number.isFinite(debounce)) {
193+
this.debounceEvent(debounce);
194+
}
195+
if (this.props.type !== 'number') {
196+
setTimeout(() => {
197+
input.setSelectionRange(cursorPosition, cursorPosition);
198+
}, 0);
199+
}
200+
} else {
201+
this.onEvent();
193202
}
194-
} else {
195-
this.onEvent();
196-
}
203+
});
197204
}
198205
}
199206

0 commit comments

Comments
 (0)