Skip to content

Commit

Permalink
FIX: Cursor in NumberEditor moved after entering a second decimal sep…
Browse files Browse the repository at this point in the history
…arator (#279)
  • Loading branch information
JindrichSusen committed Feb 16, 2022
1 parent 8f4ca00 commit e9e527a
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -129,18 +129,19 @@ export class NumberEditor extends React.Component<{
@action.bound handleChange(event: any) {
const {cleanValue, invalidCharactersBeforeCursor} = getValidCharacters(event);

const newValue = isValidNumber(cleanValue)
? cleanValue
: this.state.value;
const newState = isValidNumber(cleanValue)
? { value: cleanValue, cursorPosition: event.target.selectionStart - invalidCharactersBeforeCursor }
: { value: this.state.value, cursorPosition: event.target.selectionStart - 1 };

this.setState(
{ value: newValue, cursorPosition: event.target.selectionStart - invalidCharactersBeforeCursor },
newState,
() => {
if(this.inputRef.current){
this.inputRef.current.selectionStart = this.state.cursorPosition;
this.inputRef.current.selectionEnd = this.state.cursorPosition;
}
});

this.updateTextOverflowState();
}

Expand Down

0 comments on commit e9e527a

Please sign in to comment.