diff --git a/src/app/components/inputnumber/inputnumber.ts b/src/app/components/inputnumber/inputnumber.ts index a5b5c1a1dca..3ea7e2cf9df 100644 --- a/src/app/components/inputnumber/inputnumber.ts +++ b/src/app/components/inputnumber/inputnumber.ts @@ -444,7 +444,7 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control */ @Output() onClear: EventEmitter = new EventEmitter(); - @ViewChild('input') input!: ElementRef; + @ViewChild('input') input!: ElementRef; @ContentChildren(PrimeTemplate) templates!: QueryList; @@ -828,14 +828,21 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control break; case 'ArrowLeft': - if (!this.isNumeralChar(inputValue.charAt(selectionStart - 1))) { - event.preventDefault(); + for( let index=selectionStart; index<=inputValue.length;index++){ + const previousCharIndex = index === 0 ? 0 : index - 1; + if(this.isNumeralChar(inputValue.charAt(previousCharIndex))){ + this.input.nativeElement.setSelectionRange(index, index); + break; + } } break; case 'ArrowRight': - if (!this.isNumeralChar(inputValue.charAt(selectionStart))) { - event.preventDefault(); + for( let index=selectionEnd; index>=0;index--){ + if(this.isNumeralChar(inputValue.charAt(index))){ + this.input.nativeElement.setSelectionRange(index, index); + break; + } } break; @@ -1372,7 +1379,7 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control onInputBlur(event: Event) { this.focused = false; - let newValue = this.validateValue(this.parseValue(this.input.nativeElement.value)); + let newValue = this.validateValue(this.parseValue(this.input.nativeElement.value)).toString(); this.input.nativeElement.value = this.formatValue(newValue); this.input.nativeElement.setAttribute('aria-valuenow', newValue); this.updateModel(event, newValue); @@ -1426,10 +1433,6 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control clearInterval(this.timer); } } - - getFormatter() { - return this.numberFormat; - } } @NgModule({