primeng
Version:
[](https://badge.fury.io/js/primeng) [](https://www.npmjs.com/package/primeng) [
{"version":3,"file":"primeng-inputnumber.mjs","sources":["../../src/app/components/inputnumber/inputnumber.ts","../../src/app/components/inputnumber/primeng-inputnumber.ts"],"sourcesContent":["import { CommonModule, DOCUMENT } from '@angular/common';\nimport {\n AfterContentInit,\n ChangeDetectionStrategy,\n ChangeDetectorRef,\n Component,\n ContentChildren,\n ElementRef,\n EventEmitter,\n Inject,\n Injector,\n Input,\n NgModule,\n OnChanges,\n OnInit,\n Output,\n QueryList,\n SimpleChanges,\n TemplateRef,\n ViewChild,\n ViewEncapsulation,\n booleanAttribute,\n forwardRef,\n numberAttribute\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';\nimport { PrimeTemplate, SharedModule } from 'primeng/api';\nimport { AutoFocusModule } from 'primeng/autofocus';\nimport { ButtonModule } from 'primeng/button';\nimport { DomHandler } from 'primeng/dom';\nimport { AngleDownIcon } from 'primeng/icons/angledown';\nimport { AngleUpIcon } from 'primeng/icons/angleup';\nimport { TimesIcon } from 'primeng/icons/times';\nimport { InputTextModule } from 'primeng/inputtext';\nimport { Nullable } from 'primeng/ts-helpers';\nimport { InputNumberInputEvent } from './inputnumber.interface';\n\nexport const INPUTNUMBER_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => InputNumber),\n multi: true\n};\n/**\n * InputNumber is an input component to provide numerical input.\n * @group Components\n */\n@Component({\n selector: 'p-inputNumber',\n template: `\n <span\n [ngClass]=\"{\n 'p-inputnumber p-component': true,\n 'p-inputnumber-buttons-stacked': this.showButtons && this.buttonLayout === 'stacked',\n 'p-inputnumber-buttons-horizontal': this.showButtons && this.buttonLayout === 'horizontal',\n 'p-inputnumber-buttons-vertical': this.showButtons && this.buttonLayout === 'vertical'\n }\"\n [ngStyle]=\"style\"\n [class]=\"styleClass\"\n [attr.data-pc-name]=\"'inputnumber'\"\n [attr.data-pc-section]=\"'root'\"\n >\n <input\n pInputText\n #input\n [attr.id]=\"inputId\"\n role=\"spinbutton\"\n [ngClass]=\"'p-inputnumber-input'\"\n [ngStyle]=\"inputStyle\"\n [class]=\"inputStyleClass\"\n [value]=\"formattedValue()\"\n [attr.variant]=\"variant\"\n [attr.aria-valuemin]=\"min\"\n [attr.aria-valuemax]=\"max\"\n [attr.aria-valuenow]=\"value\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly\"\n [attr.placeholder]=\"placeholder\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledBy\"\n [attr.title]=\"title\"\n [attr.size]=\"size\"\n [attr.name]=\"name\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.maxlength]=\"maxlength\"\n [attr.tabindex]=\"tabindex\"\n [attr.aria-required]=\"ariaRequired\"\n [attr.required]=\"required\"\n [attr.min]=\"min\"\n [attr.max]=\"max\"\n inputmode=\"decimal\"\n (input)=\"onUserInput($event)\"\n (keydown)=\"onInputKeyDown($event)\"\n (keypress)=\"onInputKeyPress($event)\"\n (paste)=\"onPaste($event)\"\n (click)=\"onInputClick()\"\n (focus)=\"onInputFocus($event)\"\n (blur)=\"onInputBlur($event)\"\n [attr.data-pc-section]=\"'input'\"\n pAutoFocus\n [autofocus]=\"autofocus\"\n />\n <ng-container *ngIf=\"buttonLayout != 'vertical' && showClear && value\">\n <TimesIcon *ngIf=\"!clearIconTemplate\" [ngClass]=\"'p-inputnumber-clear-icon'\" (click)=\"clear()\" [attr.data-pc-section]=\"'clearIcon'\" />\n <span *ngIf=\"clearIconTemplate\" (click)=\"clear()\" class=\"p-inputnumber-clear-icon\" [attr.data-pc-section]=\"'clearIcon'\">\n <ng-template *ngTemplateOutlet=\"clearIconTemplate\"></ng-template>\n </span>\n </ng-container>\n <span class=\"p-inputnumber-button-group\" *ngIf=\"showButtons && buttonLayout === 'stacked'\" [attr.data-pc-section]=\"'buttonGroup'\">\n <button\n type=\"button\"\n pButton\n [ngClass]=\"{ 'p-inputnumber-button p-inputnumber-button-up': true }\"\n class=\"p-button-icon-only\"\n [class]=\"incrementButtonClass\"\n [disabled]=\"disabled\"\n tabindex=\"-1\"\n (mousedown)=\"onUpButtonMouseDown($event)\"\n (mouseup)=\"onUpButtonMouseUp()\"\n (mouseleave)=\"onUpButtonMouseLeave()\"\n (keydown)=\"onUpButtonKeyDown($event)\"\n (keyup)=\"onUpButtonKeyUp()\"\n [attr.aria-hidden]=\"true\"\n [attr.data-pc-section]=\"'incrementbutton'\"\n >\n <span *ngIf=\"incrementButtonIcon\" [ngClass]=\"incrementButtonIcon\" [attr.data-pc-section]=\"'incrementbuttonicon'\"></span>\n <ng-container *ngIf=\"!incrementButtonIcon\">\n <AngleUpIcon *ngIf=\"!incrementButtonIconTemplate\" [attr.data-pc-section]=\"'incrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"incrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n <button\n type=\"button\"\n pButton\n [ngClass]=\"{ 'p-inputnumber-button p-inputnumber-button-down': true }\"\n class=\"p-button-icon-only\"\n [class]=\"decrementButtonClass\"\n [disabled]=\"disabled\"\n tabindex=\"-1\"\n [attr.aria-hidden]=\"true\"\n (mousedown)=\"onDownButtonMouseDown($event)\"\n (mouseup)=\"onDownButtonMouseUp()\"\n (mouseleave)=\"onDownButtonMouseLeave()\"\n (keydown)=\"onDownButtonKeyDown($event)\"\n (keyup)=\"onDownButtonKeyUp()\"\n [attr.data-pc-section]=\"decrementbutton\"\n >\n <span *ngIf=\"decrementButtonIcon\" [ngClass]=\"decrementButtonIcon\" [attr.data-pc-section]=\"'decrementbuttonicon'\"></span>\n <ng-container *ngIf=\"!decrementButtonIcon\">\n <AngleDownIcon *ngIf=\"!decrementButtonIconTemplate\" [attr.data-pc-section]=\"'decrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"decrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n </span>\n <button\n *ngIf=\"showButtons && buttonLayout !== 'stacked'\"\n type=\"button\"\n pButton\n [ngClass]=\"{ 'p-inputnumber-button p-inputnumber-button-up': true }\"\n [class]=\"incrementButtonClass\"\n class=\"p-button-icon-only\"\n [disabled]=\"disabled\"\n tabindex=\"-1\"\n [attr.aria-hidden]=\"true\"\n (mousedown)=\"onUpButtonMouseDown($event)\"\n (mouseup)=\"onUpButtonMouseUp()\"\n (mouseleave)=\"onUpButtonMouseLeave()\"\n (keydown)=\"onUpButtonKeyDown($event)\"\n (keyup)=\"onUpButtonKeyUp()\"\n [attr.data-pc-section]=\"'incrementbutton'\"\n >\n <span *ngIf=\"incrementButtonIcon\" [ngClass]=\"incrementButtonIcon\" [attr.data-pc-section]=\"'incrementbuttonicon'\"></span>\n <ng-container *ngIf=\"!incrementButtonIcon\">\n <AngleUpIcon *ngIf=\"!incrementButtonIconTemplate\" [attr.data-pc-section]=\"'incrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"incrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n <button\n *ngIf=\"showButtons && buttonLayout !== 'stacked'\"\n type=\"button\"\n pButton\n [ngClass]=\"{ 'p-inputnumber-button p-inputnumber-button-down': true }\"\n class=\"p-button-icon-only\"\n [class]=\"decrementButtonClass\"\n [disabled]=\"disabled\"\n tabindex=\"-1\"\n [attr.aria-hidden]=\"true\"\n (mousedown)=\"onDownButtonMouseDown($event)\"\n (mouseup)=\"onDownButtonMouseUp()\"\n (mouseleave)=\"onDownButtonMouseLeave()\"\n (keydown)=\"onDownButtonKeyDown($event)\"\n (keyup)=\"onDownButtonKeyUp()\"\n [attr.data-pc-section]=\"'decrementbutton'\"\n >\n <span *ngIf=\"decrementButtonIcon\" [ngClass]=\"decrementButtonIcon\" [attr.data-pc-section]=\"'decrementbuttonicon'\"></span>\n <ng-container *ngIf=\"!decrementButtonIcon\">\n <AngleDownIcon *ngIf=\"!decrementButtonIconTemplate\" [attr.data-pc-section]=\"'decrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"decrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n </span>\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [INPUTNUMBER_VALUE_ACCESSOR],\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['./inputnumber.css'],\n host: {\n class: 'p-element p-inputwrapper',\n '[class.p-inputwrapper-filled]': 'filled',\n '[class.p-inputwrapper-focus]': 'focused',\n '[class.p-inputnumber-clearable]': 'showClear && buttonLayout != \"vertical\"'\n }\n})\nexport class InputNumber implements OnInit, AfterContentInit, OnChanges, ControlValueAccessor {\n /**\n * Displays spinner buttons.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) showButtons: boolean = false;\n /**\n * Whether to format the value.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) format: boolean = true;\n /**\n * Layout of the buttons, valid values are \"stacked\" (default), \"horizontal\" and \"vertical\".\n * @group Props\n */\n @Input() buttonLayout: string = 'stacked';\n /**\n * Identifier of the focus input to match a label defined for the component.\n * @group Props\n */\n @Input() inputId: string | undefined;\n /**\n * Style class of the component.\n * @group Props\n */\n @Input() styleClass: string | undefined;\n /**\n * Inline style of the component.\n * @group Props\n */\n @Input() style: { [klass: string]: any } | null | undefined;\n /**\n * Advisory information to display on input.\n * @group Props\n */\n @Input() placeholder: string | undefined;\n /**\n * Size of the input field.\n * @group Props\n */\n @Input({ transform: numberAttribute }) size: number | undefined;\n /**\n * Maximum number of character allows in the input field.\n * @group Props\n */\n @Input({ transform: numberAttribute }) maxlength: number | undefined;\n /**\n * Specifies tab order of the element.\n * @group Props\n */\n @Input({ transform: numberAttribute }) tabindex: number | undefined;\n /**\n * Title text of the input text.\n * @group Props\n */\n @Input() title: string | undefined;\n /**\n * Specifies one or more IDs in the DOM that labels the input field.\n * @group Props\n */\n @Input() ariaLabelledBy: string | undefined;\n /**\n * Used to define a string that labels the input element.\n * @group Props\n */\n @Input() ariaLabel: string | undefined;\n /**\n * Used to indicate that user input is required on an element before a form can be submitted.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) ariaRequired: boolean | undefined;\n /**\n * Name of the input field.\n * @group Props\n */\n @Input() name: string | undefined;\n /**\n * Indicates that whether the input field is required.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) required: boolean | undefined;\n /**\n * Used to define a string that autocomplete attribute the current element.\n * @group Props\n */\n @Input() autocomplete: string | undefined;\n /**\n * Mininum boundary value.\n * @group Props\n */\n @Input({ transform: numberAttribute }) min: number | undefined;\n /**\n * Maximum boundary value.\n * @group Props\n */\n @Input({ transform: numberAttribute }) max: number | undefined;\n /**\n * Style class of the increment button.\n * @group Props\n */\n @Input() incrementButtonClass: string | undefined;\n /**\n * Style class of the decrement button.\n * @group Props\n */\n @Input() decrementButtonClass: string | undefined;\n /**\n * Style class of the increment button.\n * @group Props\n */\n @Input() incrementButtonIcon: string | undefined;\n /**\n * Style class of the decrement button.\n * @group Props\n */\n @Input() decrementButtonIcon: string | undefined;\n /**\n * When present, it specifies that an input field is read-only.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) readonly: boolean = false;\n /**\n * Step factor to increment/decrement the value.\n * @group Props\n */\n @Input({ transform: numberAttribute }) step: number = 1;\n /**\n * Determines whether the input field is empty.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) allowEmpty: boolean = true;\n /**\n * Locale to be used in formatting.\n * @group Props\n */\n @Input() locale: string | undefined;\n /**\n * The locale matching algorithm to use. Possible values are \"lookup\" and \"best fit\"; the default is \"best fit\". See Locale Negotiation for details.\n * @group Props\n */\n @Input() localeMatcher: string | undefined;\n /**\n * Defines the behavior of the component, valid values are \"decimal\" and \"currency\".\n * @group Props\n */\n @Input() mode: string = 'decimal';\n /**\n * The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as \"USD\" for the US dollar, \"EUR\" for the euro, or \"CNY\" for the Chinese RMB. There is no default value; if the style is \"currency\", the currency property must be provided.\n * @group Props\n */\n @Input() currency: string | undefined;\n /**\n * How to display the currency in currency formatting. Possible values are \"symbol\" to use a localized currency symbol such as €, ü\"code\" to use the ISO currency code, \"name\" to use a localized currency name such as \"dollar\"; the default is \"symbol\".\n * @group Props\n */\n @Input() currencyDisplay: string | undefined;\n /**\n * Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) useGrouping: boolean = true;\n /**\n * Specifies the input variant of the component.\n * @group Props\n */\n @Input() variant: 'filled' | 'outlined' = 'outlined';\n /**\n * The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information).\n * @group Props\n */\n @Input({ transform: (value: unknown) => numberAttribute(value, null) }) minFractionDigits: number | undefined;\n /**\n * The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information).\n * @group Props\n */\n @Input({ transform: (value: unknown) => numberAttribute(value, null) }) maxFractionDigits: number | undefined;\n /**\n * Text to display before the value.\n * @group Props\n */\n @Input() prefix: string | undefined;\n /**\n * Text to display after the value.\n * @group Props\n */\n @Input() suffix: string | undefined;\n /**\n * Inline style of the input field.\n * @group Props\n */\n @Input() inputStyle: any;\n /**\n * Style class of the input field.\n * @group Props\n */\n @Input() inputStyleClass: string | undefined;\n /**\n * When enabled, a clear icon is displayed to clear the value.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) showClear: boolean = false;\n /**\n * When present, it specifies that the component should automatically get focus on load.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) autofocus: boolean | undefined;\n /**\n * When present, it specifies that the element should be disabled.\n * @group Props\n */\n @Input() get disabled(): boolean | undefined {\n return this._disabled;\n }\n set disabled(disabled: boolean | undefined) {\n if (disabled) this.focused = false;\n\n this._disabled = disabled;\n\n if (this.timer) this.clearTimer();\n }\n /**\n * Callback to invoke on input.\n * @param {InputNumberInputEvent} event - Custom input event.\n * @group Emits\n */\n @Output() onInput: EventEmitter<InputNumberInputEvent> = new EventEmitter<InputNumberInputEvent>();\n /**\n * Callback to invoke when the component receives focus.\n * @param {Event} event - Browser event.\n * @group Emits\n */\n @Output() onFocus: EventEmitter<Event> = new EventEmitter<Event>();\n /**\n * Callback to invoke when the component loses focus.\n * @param {Event} event - Browser event.\n * @group Emits\n */\n @Output() onBlur: EventEmitter<Event> = new EventEmitter<Event>();\n /**\n * Callback to invoke on input key press.\n * @param {KeyboardEvent} event - Keyboard event.\n * @group Emits\n */\n @Output() onKeyDown: EventEmitter<KeyboardEvent> = new EventEmitter<KeyboardEvent>();\n /**\n * Callback to invoke when clear token is clicked.\n * @group Emits\n */\n @Output() onClear: EventEmitter<void> = new EventEmitter<void>();\n\n @ViewChild('input') input!: ElementRef<HTMLInputElement>;\n\n @ContentChildren(PrimeTemplate) templates!: QueryList<PrimeTemplate>;\n\n clearIconTemplate: Nullable<TemplateRef<any>>;\n\n incrementButtonIconTemplate: Nullable<TemplateRef<any>>;\n\n decrementButtonIconTemplate: Nullable<TemplateRef<any>>;\n\n value: Nullable<number>;\n\n onModelChange: Function = () => {};\n\n onModelTouched: Function = () => {};\n\n focused: Nullable<boolean>;\n\n initialized: Nullable<boolean>;\n\n groupChar: string = '';\n\n prefixChar: string = '';\n\n suffixChar: string = '';\n\n isSpecialChar: Nullable<boolean>;\n\n timer: any;\n\n lastValue: Nullable<string>;\n\n _numeral: any;\n\n numberFormat: any;\n\n _decimal: any;\n\n _decimalChar: string;\n\n _group: any;\n\n _minusSign: any;\n\n _currency: Nullable<RegExp | string>;\n\n _prefix: Nullable<RegExp>;\n\n _suffix: Nullable<RegExp>;\n\n _index: number | any;\n\n _disabled: boolean | undefined;\n\n private ngControl: NgControl | null = null;\n\n constructor(\n @Inject(DOCUMENT) private document: Document,\n public el: ElementRef,\n private cd: ChangeDetectorRef,\n private readonly injector: Injector\n ) {}\n\n ngOnChanges(simpleChange: SimpleChanges) {\n const props = ['locale', 'localeMatcher', 'mode', 'currency', 'currencyDisplay', 'useGrouping', 'minFractionDigits', 'maxFractionDigits', 'prefix', 'suffix'];\n if (props.some((p) => !!simpleChange[p])) {\n this.updateConstructParser();\n }\n }\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch (item.getType()) {\n case 'clearicon':\n this.clearIconTemplate = item.template;\n break;\n\n case 'incrementbuttonicon':\n this.incrementButtonIconTemplate = item.template;\n break;\n\n case 'decrementbuttonicon':\n this.decrementButtonIconTemplate = item.template;\n break;\n }\n });\n }\n\n ngOnInit() {\n this.ngControl = this.injector.get(NgControl, null, { optional: true });\n\n this.constructParser();\n\n this.initialized = true;\n }\n\n getOptions() {\n return {\n localeMatcher: this.localeMatcher,\n style: this.mode,\n currency: this.currency,\n currencyDisplay: this.currencyDisplay,\n useGrouping: this.useGrouping,\n minimumFractionDigits: this.minFractionDigits ? this.minFractionDigits : undefined,\n maximumFractionDigits: this.maxFractionDigits ? this.maxFractionDigits : undefined\n };\n }\n\n constructParser() {\n this.numberFormat = new Intl.NumberFormat(this.locale, this.getOptions());\n const numerals = [...new Intl.NumberFormat(this.locale, { useGrouping: false }).format(9876543210)].reverse();\n const index = new Map(numerals.map((d, i) => [d, i]));\n this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');\n this._group = this.getGroupingExpression();\n this._minusSign = this.getMinusSignExpression();\n this._currency = this.getCurrencyExpression();\n this._decimal = this.getDecimalExpression();\n this._decimalChar = this.getDecimalChar();\n this._suffix = this.getSuffixExpression();\n this._prefix = this.getPrefixExpression();\n this._index = (d: any) => index.get(d);\n }\n\n updateConstructParser() {\n if (this.initialized) {\n this.constructParser();\n }\n }\n\n escapeRegExp(text: string): string {\n return text.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n }\n\n getDecimalExpression(): RegExp {\n const decimalChar = this.getDecimalChar();\n return new RegExp(`[${decimalChar}]`, 'g');\n }\n getDecimalChar(): string {\n const formatter = new Intl.NumberFormat(this.locale, { ...this.getOptions(), useGrouping: false });\n return formatter\n .format(1.1)\n .replace(this._currency as RegExp | string, '')\n .trim()\n .replace(this._numeral, '');\n }\n\n getGroupingExpression(): RegExp {\n const formatter = new Intl.NumberFormat(this.locale, { useGrouping: true });\n this.groupChar = formatter.format(1000000).trim().replace(this._numeral, '').charAt(0);\n return new RegExp(`[${this.groupChar}]`, 'g');\n }\n\n getMinusSignExpression(): RegExp {\n const formatter = new Intl.NumberFormat(this.locale, { useGrouping: false });\n return new RegExp(`[${formatter.format(-1).trim().replace(this._numeral, '')}]`, 'g');\n }\n\n getCurrencyExpression(): RegExp {\n if (this.currency) {\n const formatter = new Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0 });\n return new RegExp(`[${formatter.format(1).replace(/\\s/g, '').replace(this._numeral, '').replace(this._group, '')}]`, 'g');\n }\n\n return new RegExp(`[]`, 'g');\n }\n\n getPrefixExpression(): RegExp {\n if (this.prefix) {\n this.prefixChar = this.prefix;\n } else {\n const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay });\n this.prefixChar = formatter.format(1).split('1')[0];\n }\n\n return new RegExp(`${this.escapeRegExp(this.prefixChar || '')}`, 'g');\n }\n\n getSuffixExpression(): RegExp {\n if (this.suffix) {\n this.suffixChar = this.suffix;\n } else {\n const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0 });\n this.suffixChar = formatter.format(1).split('1')[1];\n }\n\n return new RegExp(`${this.escapeRegExp(this.suffixChar || '')}`, 'g');\n }\n\n formatValue(value: any) {\n if (value != null) {\n if (value === '-') {\n // Minus sign\n return value;\n }\n\n if (this.format) {\n let formatter = new Intl.NumberFormat(this.locale, this.getOptions());\n let formattedValue = formatter.format(value);\n\n if (this.prefix && value != this.prefix) {\n formattedValue = this.prefix + formattedValue;\n }\n\n if (this.suffix && value != this.suffix) {\n formattedValue = formattedValue + this.suffix;\n }\n\n return formattedValue;\n }\n\n return value.toString();\n }\n\n return '';\n }\n\n parseValue(text: any) {\n const suffixRegex = new RegExp(this._suffix, '');\n const prefixRegex = new RegExp(this._prefix, '');\n const currencyRegex = new RegExp(this._currency, '');\n\n let filteredText = text\n .replace(suffixRegex, '')\n .replace(prefixRegex, '')\n .trim()\n .replace(/\\s/g, '')\n .replace(currencyRegex, '')\n .replace(this._group, '')\n .replace(this._minusSign, '-')\n .replace(this._decimal, '.')\n .replace(this._numeral, this._index);\n\n if (filteredText) {\n if (filteredText === '-')\n // Minus sign\n return filteredText;\n\n let parsedValue = +filteredText;\n return isNaN(parsedValue) ? null : parsedValue;\n }\n\n return null;\n }\n\n repeat(event: Event, interval: number | null, dir: number) {\n if (this.readonly) {\n return;\n }\n\n let i = interval || 500;\n\n this.clearTimer();\n this.timer = setTimeout(() => {\n this.repeat(event, 40, dir);\n }, i);\n\n this.spin(event, dir);\n }\n\n spin(event: Event, dir: number) {\n let step = this.step * dir;\n let currentValue = this.parseValue(this.input?.nativeElement.value) || 0;\n let newValue = this.validateValue((currentValue as number) + step);\n if (this.maxlength && this.maxlength < this.formatValue(newValue).length) {\n return;\n }\n this.updateInput(newValue, null, 'spin', null);\n this.updateModel(event, newValue);\n\n this.handleOnInput(event, currentValue, newValue);\n }\n\n clear() {\n this.value = null;\n this.onModelChange(this.value);\n this.onClear.emit();\n }\n\n onUpButtonMouseDown(event: MouseEvent) {\n if (event.button === 2) {\n this.clearTimer();\n return;\n }\n\n if (!this.disabled) {\n this.input?.nativeElement.focus();\n this.repeat(event, null, 1);\n event.preventDefault();\n }\n }\n\n onUpButtonMouseUp() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onUpButtonMouseLeave() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onUpButtonKeyDown(event: KeyboardEvent) {\n if (event.keyCode === 32 || event.keyCode === 13) {\n this.repeat(event, null, 1);\n }\n }\n\n onUpButtonKeyUp() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onDownButtonMouseDown(event: MouseEvent) {\n if (event.button === 2) {\n this.clearTimer();\n return;\n }\n if (!this.disabled) {\n this.input?.nativeElement.focus();\n this.repeat(event, null, -1);\n event.preventDefault();\n }\n }\n\n onDownButtonMouseUp() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onDownButtonMouseLeave() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onDownButtonKeyUp() {\n if (!this.disabled) {\n this.clearTimer();\n }\n }\n\n onDownButtonKeyDown(event: KeyboardEvent) {\n if (event.keyCode === 32 || event.keyCode === 13) {\n this.repeat(event, null, -1);\n }\n }\n\n onUserInput(event: Event) {\n if (this.readonly) {\n return;\n }\n\n if (this.isSpecialChar) {\n (event.target as HTMLInputElement).value = this.lastValue as string;\n }\n this.isSpecialChar = false;\n }\n\n onInputKeyDown(event: KeyboardEvent) {\n if (this.readonly) {\n return;\n }\n\n this.lastValue = (event.target as HTMLInputElement).value;\n if ((event as KeyboardEvent).shiftKey || (event as KeyboardEvent).altKey) {\n this.isSpecialChar = true;\n return;\n }\n\n let selectionStart = (event.target as HTMLInputElement).selectionStart as number;\n let selectionEnd = (event.target as HTMLInputElement).selectionEnd as number;\n let inputValue = (event.target as HTMLInputElement).value as string;\n let newValueStr = null;\n\n if (event.altKey) {\n event.preventDefault();\n }\n\n switch (event.key) {\n case 'ArrowUp':\n this.spin(event, 1);\n event.preventDefault();\n break;\n\n case 'ArrowDown':\n this.spin(event, -1);\n event.preventDefault();\n break;\n\n case 'ArrowLeft':\n for (let index = selectionStart; index <= inputValue.length; index++) {\n const previousCharIndex = index === 0 ? 0 : index - 1;\n if (this.isNumeralChar(inputValue.charAt(previousCharIndex))) {\n this.input.nativeElement.setSelectionRange(index, index);\n break;\n }\n }\n break;\n\n case 'ArrowRight':\n for (let index = selectionEnd; index >= 0; index--) {\n if (this.isNumeralChar(inputValue.charAt(index))) {\n this.input.nativeElement.setSelectionRange(index, index);\n break;\n }\n }\n break;\n\n case 'Tab':\n case 'Enter':\n newValueStr = this.validateValue(this.parseValue(this.input.nativeElement.value));\n this.input.nativeElement.value = this.formatValue(newValueStr);\n this.input.nativeElement.setAttribute('aria-valuenow', newValueStr);\n this.updateModel(event, newValueStr);\n break;\n\n case 'Backspace': {\n event.preventDefault();\n\n if (selectionStart === selectionEnd) {\n if ((selectionStart == 1 && this.prefix) || (selectionStart == inputValue.length && this.suffix)) {\n break;\n }\n\n const deleteChar = inputValue.charAt(selectionStart - 1);\n const { decimalCharIndex, decimalCharIndexWithoutPrefix } = this.getDecimalCharIndexes(inputValue);\n\n if (this.isNumeralChar(deleteChar)) {\n const decimalLength = this.getDecimalLength(inputValue);\n\n if (this._group.test(deleteChar)) {\n this._group.lastIndex = 0;\n newValueStr = inputValue.slice(0, selectionStart - 2) + inputValue.slice(selectionStart - 1);\n } else if (this._decimal.test(deleteChar)) {\n this._decimal.lastIndex = 0;\n\n if (decimalLength) {\n this.input?.nativeElement.setSelectionRange(selectionStart - 1, selectionStart - 1);\n } else {\n newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart);\n }\n } else if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {\n const insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < decimalLength ? '' : '0';\n newValueStr = inputValue.slice(0, selectionStart - 1) + insertedText + inputValue.slice(selectionStart);\n } else if (decimalCharIndexWithoutPrefix === 1) {\n newValueStr = inputValue.slice(0, selectionStart - 1) + '0' + inputValue.slice(selectionStart);\n newValueStr = (this.parseValue(newValueStr) as number) > 0 ? newValueStr : '';\n } else {\n newValueStr = inputValue.slice(0, selectionStart - 1) + inputValue.slice(selectionStart);\n }\n } else if (this.mode === 'currency' && deleteChar.search(this._currency) != -1) {\n newValueStr = inputValue.slice(1);\n }\n\n this.updateValue(event, newValueStr, null, 'delete-single');\n } else {\n newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd);\n this.updateValue(event, newValueStr, null, 'delete-range');\n }\n\n break;\n }\n\n case 'Delete':\n event.preventDefault();\n\n if (selectionStart === selectionEnd) {\n if ((selectionStart == 0 && this.prefix) || (selectionStart == inputValue.length - 1 && this.suffix)) {\n break;\n }\n const deleteChar = inputValue.charAt(selectionStart);\n const { decimalCharIndex, decimalCharIndexWithoutPrefix } = this.getDecimalCharIndexes(inputValue);\n\n if (this.isNumeralChar(deleteChar)) {\n const decimalLength = this.getDecimalLength(inputValue);\n\n if (this._group.test(deleteChar)) {\n this._group.lastIndex = 0;\n newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 2);\n } else if (this._decimal.test(deleteChar)) {\n this._decimal.lastIndex = 0;\n\n if (decimalLength) {\n this.input?.nativeElement.setSelectionRange(selectionStart + 1, selectionStart + 1);\n } else {\n newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1);\n }\n } else if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {\n const insertedText = this.isDecimalMode() && (this.minFractionDigits || 0) < decimalLength ? '' : '0';\n newValueStr = inputValue.slice(0, selectionStart) + insertedText + inputValue.slice(selectionStart + 1);\n } else if (decimalCharIndexWithoutPrefix === 1) {\n newValueStr = inputValue.slice(0, selectionStart) + '0' + inputValue.slice(selectionStart + 1);\n newValueStr = (this.parseValue(newValueStr) as number) > 0 ? newValueStr : '';\n } else {\n newValueStr = inputValue.slice(0, selectionStart) + inputValue.slice(selectionStart + 1);\n }\n }\n\n this.updateValue(event, newValueStr as string, null, 'delete-back-single');\n } else {\n newValueStr = this.deleteRange(inputValue, selectionStart, selectionEnd);\n this.updateValue(event, newValueStr, null, 'delete-range');\n }\n break;\n\n case 'Home':\n if (this.min) {\n this.updateModel(event, this.min);\n event.preventDefault();\n }\n break;\n\n case 'End':\n if (this.max) {\n this.updateModel(event, this.max);\n event.preventDefault();\n }\n break;\n\n default:\n break;\n }\n\n this.onKeyDown.emit(event);\n }\n\n onInputKeyPress(event: KeyboardEvent) {\n if (this.readonly) {\n return;\n }\n\n let code = event.which || event.keyCode;\n let char = String.fromCharCode(code);\n let isDecimalSign = this.isDecimalSign(char);\n const isMinusSign = this.isMinusSign(char);\n\n if (code != 13) {\n event.preventDefault();\n }\n if (!isDecimalSign && event.code === 'NumpadDecimal') {\n isDecimalSign = true;\n char = this._decimalChar;\n code = char.charCodeAt(0);\n }\n const newValue = this.parseValue(this.input.nativeElement.value + char);\n const newValueStr = newValue != null ? newValue.toString() : '';\n\n if (this.maxlength && this.getSelectedText()?.length == this.maxlength) {\n this.insert(event, char, { isDecimalSign, isMinusSign });\n return;\n }\n\n if (this.maxlength && newValueStr.length > this.maxlength) {\n return;\n }\n\n if ((48 <= code && code <= 57) || isMinusSign || isDecimalSign) {\n this.insert(event, char, { isDecimalSign, isMinusSign });\n }\n }\n\n private getSelectedText() {\n return (\n window\n ?.getSelection()\n ?.toString()\n .replaceAll(/[^0-9']/g, '') || ''\n );\n }\n\n onPaste(event: ClipboardEvent) {\n if (!this.disabled && !this.readonly) {\n event.preventDefault();\n let data = (event.clipboardData || (this.document as any).defaultView['clipboardData']).getData('Text');\n if (data) {\n if (this.maxlength) {\n data = data.toString().substring(0, this.maxlength);\n }\n\n let filteredData = this.parseValue(data);\n if (filteredData != null) {\n this.insert(event, filteredData.toString());\n }\n }\n }\n }\n\n allowMinusSign() {\n return this.min == null || this.min < 0;\n }\n\n isMinusSign(char: string) {\n if (this._minusSign.test(char) || char === '-') {\n this._minusSign.lastIndex = 0;\n return true;\n }\n\n return false;\n }\n\n isDecimalSign(char: string) {\n if (this._decimal.test(char)) {\n this._decimal.lastIndex = 0;\n return true;\n }\n\n return false;\n }\n\n isDecimalMode() {\n return this.mode === 'decimal';\n }\n\n getDecimalCharIndexes(val: string) {\n let decimalCharIndex = val.search(this._decimal);\n this._decimal.lastIndex = 0;\n\n const filteredVal = val\n .replace(this._prefix as RegExp, '')\n .trim()\n .replace(/\\s/g, '')\n .replace(this._currency as RegExp, '');\n const decimalCharIndexWithoutPrefix = filteredVal.search(this._decimal);\n this._decimal.lastIndex = 0;\n\n return { decimalCharIndex, decimalCharIndexWithoutPrefix };\n }\n\n getCharIndexes(val: string) {\n const decimalCharIndex = val.search(this._decimal);\n this._decimal.lastIndex = 0;\n const minusCharIndex = val.search(this._minusSign);\n this._minusSign.lastIndex = 0;\n const suffixCharIndex = val.search(this._suffix as RegExp);\n (this._suffix as RegExp).lastIndex = 0;\n const currencyCharIndex = val.search(this._currency as RegExp);\n (this._currency as RegExp).lastIndex = 0;\n\n return { decimalCharIndex, minusCharIndex, suffixCharIndex, currencyCharIndex };\n }\n\n insert(event: Event, text: string, sign = { isDecimalSign: false, isMinusSign: false }) {\n const minusCharIndexOnText = text.search(this._minusSign);\n this._minusSign.lastIndex = 0;\n if (!this.allowMinusSign() && minusCharIndexOnText !== -1) {\n return;\n }\n\n let selectionStart = this.input?.nativeElement.selectionStart;\n let selectionEnd = this.input?.nativeElement.selectionEnd;\n let inputValue = this.input?.nativeElement.value.trim();\n const { decimalCharIndex, minusCharIndex, suffixCharIndex, currencyCharIndex } = this.getCharIndexes(inputValue);\n let newValueStr;\n\n if (sign.isMinusSign) {\n if (selectionStart === 0) {\n newValueStr = inputValue;\n if (minusCharIndex === -1 || selectionEnd !== 0) {\n newValueStr = this.insertText(inputValue, text, 0, selectionEnd);\n }\n\n this.updateValue(event, newValueStr, text, 'insert');\n }\n } else if (sign.isDecimalSign) {\n if (decimalCharIndex > 0 && selectionStart === decimalCharIndex) {\n this.updateValue(event, inputValue, text, 'insert');\n } else if (decimalCharIndex > selectionStart && decimalCharIndex < selectionEnd) {\n newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);\n this.updateValue(event, newValueStr, text, 'insert');\n } else if (decimalCharIndex === -1 && this.maxFractionDigits) {\n newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);\n this.updateValue(event, newValueStr, text, 'insert');\n }\n } else {\n const maxFractionDigits = this.numberFormat.resolvedOptions().maximumFractionDigits;\n const operation = selectionStart !== selectionEnd ? 'range-insert' : 'insert';\n\n if (decimalCharIndex > 0 && selectionStart > decimalCharIndex) {\n if (selectionStart + text.length - (decimalCharIndex + 1) <= maxFractionDigits) {\n const charIndex = currencyCharIndex >= selectionStart ? currencyCharIndex - 1 : suffixCharIndex >= selectionStart ? suffixCharIndex : inputValue.length;\n\n newValueStr = inputValue.slice(0, selectionStart) + text + inputValue.slice(selectionStart + text.length, charIndex) + inputValue.slice(charIndex);\n this.updateValue(event, newValueStr, text, operation);\n }\n } else {\n newValueStr = this.insertText(inputValue, text, selectionStart, selectionEnd);\n this.updateValue(event, newValueStr, text, operation);\n }\n }\n }\n\n insertText(value: string, text: string, start: number, end: number) {\n let textSplit = text === '.' ? text : text.split('.');\n\n if (textSplit.length === 2) {\n const decimalCharIndex = value.slice(start, end).search(this._decimal);\n this._decimal.lastIndex = 0;\n return decimalCharIndex > 0 ? value.slice(0, start) + this.formatValue(text) + value.slice(end) : value || this.formatValue(text);\n } else if (end - start === value.length) {\n return this.formatValue(text);\n } else if (start === 0) {\n return text + value.slice(end);\n } else if (end === value.length) {\n return value.slice(0, start) + text;\n } else {\n return value.slice(0, start) + text + value.slice(end);\n }\n }\n\n deleteRange(value: string, start: number, end: number) {\n let newValueStr;\n\n if (end - start === value.length) newValueStr = '';\n else if (start === 0) newValueStr = value.slice(end);\n else if (end === value.length) newValueStr = value.slice(0, start);\n else newValueStr = value.slice(0, start) + value.slice(end);\n\n return newValueStr;\n }\n\n initCursor() {\n let selectionStart = this.input?.nativeElement.selectionStart;\n let selectionEnd = this.input?.nativeElement.selectionEnd;\n let inputValue = this.input?.nativeElement.value;\n let valueLength = inputValue.length;\n let index = null;\n\n // remove prefix\n let prefixLength = (this.prefixChar || '').length;\n inputValue = inputValue.replace(this._prefix, '');\n\n // Will allow selecting whole prefix. But not a part of it.\n // Negative values will trigger clauses after this to fix the cursor position.\n if (selectionStart === selectionEnd || selectionStart !== 0 || selectionEnd < prefixLength) {\n selectionStart -= prefixLength;\n }\n\n let char = inputValue.charAt(selectionStart);\n if (this.isNumeralChar(char)) {\n return selectionStart + prefixLength;\n }\n\n //left\n let i = selectionStart - 1;\n while (i >= 0) {\n char = inputValue.charAt(i);\n if (this.isNumeralChar(char)) {\n index = i + prefixLength;\n break;\n } else {\n i--;\n }\n }\n\n if (index !== null) {\n this.input?.nativeElement.setSelectionRange(index + 1, index + 1);\n } else {\n i = selectionStart;\n while (i < valueLength) {\n char = inputValue.charAt(i);\n if (this.isNumeralChar(char)) {\n index = i + prefixLength;\n break;\n } else {\n i++;\n }\n }\n\n if (index !== null) {\n this.input?.nativeElement.setSelectionRange(index, index);\n }\n }\n\n return index || 0;\n }\n\n onInputClick() {\n const currentValue = this.input?.nativeElement.value;\n\n if (!this.readonly && currentValue !== DomHandler.getSelection()) {\n this.initCursor();\n }\n }\n\n isNumeralChar(char: string) {\n if (char.length === 1 && (this._numeral.test(char) || this._decimal.test(char) || this._group.test(char) || this._minusSign.test(char))) {\n this.resetRegex();\n return true;\n }\n\n return false;\n }\n\n resetRegex() {\n this._numeral.lastIndex = 0;\n this._decimal.lastIndex = 0;\n this._group.lastIndex = 0;\n this._minusSign.lastIndex = 0;\n }\n\n updateValue(event: Event, valueStr: Nullable<string>, insertedValueStr: Nullable<string>, operation: Nullable<string>) {\n let currentValue = this.input?.nativeElement.value;\n let newValue = null;\n\n if (valueStr != null) {\n newValue = this.parseValue(valueStr);\n newValue = !newValue && !this.allowEmpty ? 0 : newValue;\n this.updateInput(newValue, insertedValueStr, operation, valueStr);\n\n this.handleOnInput(event, currentValue, newValue);\n }\n }\n\n handleOnInput(event: Event, currentValue: string, newValue: any) {\n if (this.isValueChanged(currentValue, newValue)) {\n (this.input as ElementRef).nativeElement.value = this.formatValue(newValue);\n this.input?.nativeElement.setAttribute('aria-valuenow', newValue);\n this.updateModel(event, newValue);\n this.onInput.emit({ originalEvent: event, value: newValue, formattedValue: currentValue });\n }\n }\n\n isValueChanged(currentValue: string, newValue: string) {\n if (newValue === null && currentValue !== null) {\n return true;\n }\n\n if (newValue != null) {\n let parsedCurrentValue = typeof currentValue === 'string' ? this.parseValue(currentValue) : currentValue;\n retur