Skip to content

Commit

Permalink
Fixed #10565 - Input number caret issue with negatives
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 7, 2021
1 parent a76075f commit 37ad800
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,12 @@ export class InputNumber implements OnInit,ControlValueAccessor {
this._group.lastIndex = 0;
this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
}
else if (inputValue === '-' && operation === 'insert') {
this.input.nativeElement.setSelectionRange(0, 0);
const index = this.initCursor();
const selectionEnd = index + insertedValueStr.length + 1;
this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
}
else {
selectionEnd = selectionEnd + (newLength - currentLength);
this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
Expand All @@ -939,7 +945,7 @@ export class InputNumber implements OnInit,ControlValueAccessor {
let decimalCharIndex = val2.search(this._decimal);
this._decimal.lastIndex = 0;

return val1.split(this._decimal)[0] + (decimalCharIndex !== -1 ? val2.slice(decimalCharIndex) : '');
return decimalCharIndex !== -1 ? (val1.split(this._decimal)[0] + val2.slice(decimalCharIndex)) : val1;
}

return val1;
Expand Down

0 comments on commit 37ad800

Please sign in to comment.