Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #14869 - LeftArrowKey not working for selected input #14871

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control
*/
@Output() onClear: EventEmitter<void> = new EventEmitter<void>();

@ViewChild('input') input!: ElementRef;
@ViewChild('input') input!: ElementRef<HTMLInputElement>;

@ContentChildren(PrimeTemplate) templates!: QueryList<PrimeTemplate>;

Expand Down Expand Up @@ -824,14 +824,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;

Expand Down Expand Up @@ -1363,7 +1370,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);
Expand Down Expand Up @@ -1417,10 +1424,6 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control
clearInterval(this.timer);
}
}

getFormatter() {
return this.numberFormat;
}
}

@NgModule({
Expand Down