Skip to content

Commit a2f28f4

Browse files
duxorNepipenkoIgor
authored andcommitted
fix: put the cursor at the end if actual length reached on input (JsDaddy#653)
1 parent 4c13af2 commit a2f28f4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

projects/ngx-mask-lib/src/lib/mask.directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ export class MaskDirective implements ControlValueAccessor, OnChanges {
225225
return;
226226
}
227227
this._position = this._position === 1 && this._inputValue.length === 1 ? null : this._position;
228-
const positionToApply: number = this._position
228+
let positionToApply: number = this._position
229229
? this._inputValue.length + position + caretShift
230230
: position + (this._code === 'Backspace' && !backspaceShift ? 0 : caretShift);
231+
if (positionToApply > this._getActualInputLength()) {
232+
positionToApply = this._getActualInputLength();
233+
}
231234
el.setSelectionRange(positionToApply, positionToApply);
232235
if ((this.maskExpression.includes('H') || this.maskExpression.includes('M')) && caretShift === 0) {
233236
el.setSelectionRange((el.selectionStart as number) + 1, (el.selectionStart as number) + 1);

0 commit comments

Comments
 (0)