diff --git a/src/app/components/inputnumber/inputnumber.ts b/src/app/components/inputnumber/inputnumber.ts index 015b0c44ed4..f7655748536 100644 --- a/src/app/components/inputnumber/inputnumber.ts +++ b/src/app/components/inputnumber/inputnumber.ts @@ -917,6 +917,12 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control const newValue = this.parseValue(this.input.nativeElement.value + char); const newValueStr = newValue != null ? newValue.toString() : ''; + + if (this.maxlength && this.getSelectedText()?.length == this.maxlength) { + this.insert(event, char, { isDecimalSign, isMinusSign }); + return; + } + if (this.maxlength && newValueStr.length > this.maxlength) { return; } @@ -926,6 +932,15 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control } } + private getSelectedText() { + return ( + window + ?.getSelection() + ?.toString() + .replaceAll(/[^0-9']/g, '') || '' + ); + } + onPaste(event: ClipboardEvent) { if (!this.disabled && !this.readonly) { event.preventDefault();