Skip to content

Commit

Permalink
Fix plotly#2612: unexpected behaviour of the cursor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rodasarede committed Jul 22, 2024
1 parent c847882 commit a3b4673
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions components/dash-core-components/src/components/Input.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,23 @@ export default class Input extends PureComponent {

onChange() {
const {debounce} = this.props;
if (debounce) {
if (Number.isFinite(debounce)) {
this.debounceEvent(debounce);
}
if (this.props.type !== 'number') {
this.setState({value: this.input.current.value});
const input = this.input.current;
const cursorPosition = input.selectionStart;
const currentValue = input.value;
this.setState({value: currentValue}, () => {
if (debounce) {
if (Number.isFinite(debounce)) {
this.debounceEvent(debounce);
}
if (this.props.type !== 'number') {
setTimeout(() => {
input.setSelectionRange(cursorPosition, cursorPosition);
}, 0);
}
} else {
this.onEvent();
}
} else {
this.onEvent();
}
});
}
}

Expand Down

0 comments on commit a3b4673

Please sign in to comment.