UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

1 lines 112 kB
{"version":3,"file":"primeng-inputnumber.mjs","sources":["../../src/inputnumber/style/inputnumberstyle.ts","../../src/inputnumber/inputnumber.ts","../../src/inputnumber/primeng-inputnumber.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { BaseStyle } from 'primeng/base';\n\nconst theme = ({ dt }) => `\n.p-inputnumber {\n display: inline-flex;\n position: relative;\n}\n\n.p-inputnumber-button {\n display: flex;\n align-items: center;\n justify-content: center;\n flex: 0 0 auto;\n cursor: pointer;\n background: ${dt('inputnumber.button.background')};\n color: ${dt('inputnumber.button.color')};\n width: ${dt('inputnumber.button.width')};\n transition: background ${dt('inputnumber.transition.duration')}, color ${dt('inputnumber.transition.duration')}, border-color ${dt('inputnumber.transition.duration')}, outline-color ${dt('inputnumber.transition.duration')};\n}\n\n.p-inputnumber-clear-icon {\n position: absolute;\n top: 50%;\n margin-top: -0.5rem;\n cursor: pointer;\n right: 0.75rem;\n color: ${dt('inputnumber.button.color')};\n}\n\n.p-inputnumber-button:hover {\n background: ${dt('inputnumber.button.hover.background')};\n color: ${dt('inputnumber.button.hover.color')};\n}\n\n.p-inputnumber-button:active {\n background: ${dt('inputnumber.button.active.background')};\n color: ${dt('inputnumber.button.active.color')};\n}\n\n.p-inputnumber-stacked .p-inputnumber-button {\n position: relative;\n border: 0 none;\n}\n\n.p-inputnumber-stacked .p-inputnumber-button-group {\n display: flex;\n flex-direction: column;\n position: absolute;\n inset-block-start: 1px;\n inset-inline-end: 1px;\n height: calc(100% - 2px);\n z-index: 1;\n}\n\n.p-inputnumber-stacked .p-inputnumber-increment-button {\n padding: 0;\n border-start-end-radius: calc(${dt('inputnumber.button.border.radius')} - 1px);\n}\n\n.p-inputnumber-stacked .p-inputnumber-decrement-button {\n padding: 0;\n border-end-end-radius: calc(${dt('inputnumber.button.border.radius')} - 1px);\n}\n\n.p-inputnumber-stacked .p-inputnumber-button {\n flex: 1 1 auto;\n border: 0 none;\n}\n\n.p-inputnumber-horizontal .p-inputnumber-button {\n border: 1px solid ${dt('inputnumber.button.border.color')};\n}\n\n.p-inputnumber-horizontal .p-inputnumber-button:hover {\n border-color: ${dt('inputnumber.button.hover.border.color')};\n}\n\n.p-inputnumber-horizontal .p-inputnumber-button:active {\n border-color: ${dt('inputnumber.button.active.border.color')};\n}\n\n.p-inputnumber-horizontal .p-inputnumber-increment-button {\n order: 3;\n border-start-end-radius: ${dt('inputnumber.button.border.radius')};\n border-end-end-radius: ${dt('inputnumber.button.border.radius')};\n border-inline-start: 0 none;\n}\n\n.p-inputnumber-horizontal .p-inputnumber-input {\n order: 2;\n border-radius: 0;\n}\n\n.p-inputnumber-horizontal .p-inputnumber-decrement-button {\n order: 1;\n border-start-start-radius: ${dt('inputnumber.button.border.radius')};\n border-end-start-radius: ${dt('inputnumber.button.border.radius')};\n border-inline-end: 0 none;\n}\n\n.p-floatlabel:has(.p-inputnumber-horizontal) label {\n margin-inline-start: ${dt('inputnumber.button.width')};\n}\n\n.p-inputnumber-vertical {\n flex-direction: column;\n}\n\n.p-inputnumber-vertical .p-inputnumber-button {\n border: 1px solid ${dt('inputnumber.button.border.color')};\n padding-block: ${dt('inputnumber.button.vertical.padding')};\n padding-inline: 0;\n}\n\n.p-inputnumber-vertical .p-inputnumber-button:hover {\n border-color: ${dt('inputnumber.button.hover.border.color')};\n}\n\n.p-inputnumber-vertical .p-inputnumber-button:active {\n border-color: ${dt('inputnumber.button.active.border.color')};\n}\n\n.p-inputnumber-vertical .p-inputnumber-increment-button {\n order: 1;\n border-start-start-radius: ${dt('inputnumber.button.border.radius')};\n border-start-end-radius: ${dt('inputnumber.button.border.radius')};\n width: 100%;\n border-block-end: 0 none;\n}\n\n.p-inputnumber-vertical .p-inputnumber-input {\n order: 2;\n border-radius: 0;\n text-align: center;\n}\n\n.p-inputnumber-vertical .p-inputnumber-decrement-button {\n order: 3;\n border-end-start-radius: ${dt('inputnumber.button.border.radius')};\n border-end-end-radius: ${dt('inputnumber.button.border.radius')};\n width: 100%;\n border-block-start: 0 none;\n}\n\n.p-inputnumber-input {\n flex: 1 1 auto;\n}\n\n.p-inputnumber-fluid {\n width: 100%;\n}\n\n.p-inputnumber-fluid .p-inputnumber-input {\n width: 1%;\n}\n\n.p-inputnumber-fluid.p-inputnumber-vertical .p-inputnumber-input {\n width: 100%;\n}\n\n.p-inputnumber:has(.p-inputtext-sm) .p-inputnumber-button .p-icon {\n font-size: ${dt('form.field.sm.font.size')};\n width: ${dt('form.field.sm.font.size')};\n height: ${dt('form.field.sm.font.size')};\n}\n\n.p-inputnumber:has(.p-inputtext-lg) .p-inputnumber-button .p-icon {\n font-size: ${dt('form.field.lg.font.size')};\n width: ${dt('form.field.lg.font.size')};\n height: ${dt('form.field.lg.font.size')};\n}\n\np-inputnumber.ng-invalid.ng-dirty > .p-inputtext {\n border-color: ${dt('inputtext.invalid.border.color')};\n}\n\np-inputnumber.ng-invalid.ng-dirty > .p-inputtext:enabled:focus {\n border-color: ${dt('inputtext.focus.border.color')};\n}\n\np-inputnumber.ng-invalid.ng-dirty > .p-inputtext::placeholder {\n color: ${dt('inputtext.invalid.placeholder.color')};\n}\n`;\n\nconst classes = {\n root: ({ instance }) => ({\n 'p-inputnumber p-component p-inputwrapper': true,\n 'p-inputwrapper-filled': instance.filled || instance.allowEmpty === false,\n 'p-inputwrapper-focus': instance.focused,\n 'p-inputnumber-stacked': instance.showButtons && instance.buttonLayout === 'stacked',\n 'p-inputnumber-horizontal': instance.showButtons && instance.buttonLayout === 'horizontal',\n 'p-inputnumber-vertical': instance.showButtons && instance.buttonLayout === 'vertical',\n 'p-inputnumber-fluid': instance.hasFluid\n }),\n pcInput: 'p-inputnumber-input',\n buttonGroup: 'p-inputnumber-button-group',\n incrementButton: ({ instance }) => ({\n 'p-inputnumber-button p-inputnumber-increment-button': true,\n 'p-disabled': instance.showButtons && instance.max !== null && instance.maxlength\n }),\n decrementButton: ({ instance }) => ({\n 'p-inputnumber-button p-inputnumber-decrement-button': true,\n 'p-disabled': instance.showButtons && instance.min !== null && instance.minlength\n })\n};\n\n@Injectable()\nexport class InputNumberStyle extends BaseStyle {\n name = 'inputnumber';\n\n theme = theme;\n\n classes = classes;\n}\n\n/**\n *\n * InputNumber is an input component to provide numerical input.\n *\n * [Live Demo](https://www.primeng.org/inputnumber/)\n *\n * @module inputnumberstyle\n *\n */\n\nexport enum InputNumberClasses {\n /**\n * Class name of the root element\n */\n root = 'p-inputnumber',\n /**\n * Class name of the input element\n */\n pcInput = 'p-inputnumber-input',\n /**\n * Class name of the button group element\n */\n buttonGroup = 'p-inputnumber-button-group',\n /**\n * Class name of the increment button element\n */\n incrementButton = 'p-inputnumber-increment-button',\n /**\n * Class name of the decrement button element\n */\n decrementButton = 'p-inputnumber-decrement-button'\n}\n\nexport interface InputNumberStyle extends BaseStyle {}\n","import { CommonModule } from '@angular/common';\nimport {\n AfterContentInit,\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n ContentChild,\n ContentChildren,\n ElementRef,\n EventEmitter,\n forwardRef,\n HostBinding,\n inject,\n Injector,\n Input,\n NgModule,\n numberAttribute,\n OnChanges,\n OnInit,\n Output,\n QueryList,\n SimpleChanges,\n TemplateRef,\n ViewChild,\n ViewEncapsulation\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';\nimport { getSelection } from '@primeuix/utils';\nimport { PrimeTemplate, SharedModule } from 'primeng/api';\nimport { AutoFocus } from 'primeng/autofocus';\nimport { BaseComponent } from 'primeng/basecomponent';\nimport { AngleDownIcon, AngleUpIcon, TimesIcon } from 'primeng/icons';\nimport { InputText } from 'primeng/inputtext';\nimport { Nullable } from 'primeng/ts-helpers';\nimport { InputNumberInputEvent } from './inputnumber.interface';\nimport { InputNumberStyle } from './style/inputnumberstyle';\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, p-inputnumber, p-input-number',\n standalone: true,\n imports: [CommonModule, InputText, AutoFocus, TimesIcon, AngleUpIcon, AngleDownIcon, SharedModule],\n template: `\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 [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 [pSize]=\"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]=\"autofocus\"\n [fluid]=\"hasFluid\"\n />\n <ng-container *ngIf=\"buttonLayout != 'vertical' && showClear && value\">\n <TimesIcon *ngIf=\"!clearIconTemplate && !_clearIconTemplate\" [ngClass]=\"'p-inputnumber-clear-icon'\" (click)=\"clear()\" [attr.data-pc-section]=\"'clearIcon'\" />\n <span *ngIf=\"clearIconTemplate || _clearIconTemplate\" (click)=\"clear()\" class=\"p-inputnumber-clear-icon\" [attr.data-pc-section]=\"'clearIcon'\">\n <ng-template *ngTemplateOutlet=\"clearIconTemplate || _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 [ngClass]=\"_incrementButtonClass\"\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 && !_incrementButtonIconTemplate\" [attr.data-pc-section]=\"'incrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"incrementButtonIconTemplate || _incrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n\n <button\n type=\"button\"\n [ngClass]=\"_decrementButtonClass\"\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 && !_decrementButtonIconTemplate\" [attr.data-pc-section]=\"'decrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"decrementButtonIconTemplate || _decrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n </span>\n <button\n *ngIf=\"showButtons && buttonLayout !== 'stacked'\"\n type=\"button\"\n [ngClass]=\"_incrementButtonClass\"\n [class]=\"incrementButtonClass\"\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 && !_incrementButtonIconTemplate\" [attr.data-pc-section]=\"'incrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"incrementButtonIconTemplate || _incrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n <button\n *ngIf=\"showButtons && buttonLayout !== 'stacked'\"\n type=\"button\"\n [ngClass]=\"_decrementButtonClass\"\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 && !_decrementButtonIconTemplate\" [attr.data-pc-section]=\"'decrementbuttonicon'\" />\n <ng-template *ngTemplateOutlet=\"decrementButtonIconTemplate || _decrementButtonIconTemplate\"></ng-template>\n </ng-container>\n </button>\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [INPUTNUMBER_VALUE_ACCESSOR, InputNumberStyle],\n encapsulation: ViewEncapsulation.None,\n host: {\n '[attr.data-pc-name]': \"'inputnumber'\",\n '[attr.data-pc-section]': \"'root'\",\n style: 'style'\n }\n})\nexport class InputNumber extends BaseComponent 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 * Defines the size of the component.\n * @group Props\n */\n @Input() size: 'large' | 'small';\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: any;\n /**\n * Defines the behavior of the component, valid values are \"decimal\" and \"currency\".\n * @group Props\n */\n @Input() mode: string | any = '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 | any;\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';\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 * Spans 100% width of the container when enabled.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) fluid: boolean = false;\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 /**\n * Template of the clear icon.\n * @group Templates\n */\n @ContentChild('clearicon', { descendants: false }) clearIconTemplate: Nullable<TemplateRef<any>>;\n /**\n * Template of the increment button icon.\n * @group Templates\n */\n @ContentChild('incrementbuttonicon', { descendants: false }) incrementButtonIconTemplate: Nullable<TemplateRef<any>>;\n\n /**\n * Template of the decrement button icon.\n * @group Templates\n */\n @ContentChild('decrementbuttonicon', { descendants: false }) decrementButtonIconTemplate: Nullable<TemplateRef<any>>;\n\n @ContentChildren(PrimeTemplate) templates!: QueryList<PrimeTemplate>;\n\n @ViewChild('input') input!: ElementRef<HTMLInputElement>;\n\n _clearIconTemplate: TemplateRef<any> | undefined;\n\n _incrementButtonIconTemplate: TemplateRef<any> | undefined;\n\n _decrementButtonIconTemplate: TemplateRef<any> | undefined;\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 _componentStyle = inject(InputNumberStyle);\n\n private ngControl: NgControl | null = null;\n\n get _rootClass() {\n return this._componentStyle.classes.root({ instance: this });\n }\n\n get hasFluid() {\n const nativeElement = this.el.nativeElement;\n const fluidComponent = nativeElement.closest('p-fluid');\n return this.fluid || !!fluidComponent;\n }\n\n get _incrementButtonClass() {\n return this._componentStyle.classes.incrementButton({ instance: this });\n }\n\n get _decrementButtonClass() {\n return this._componentStyle.classes.decrementButton({ instance: this });\n }\n\n constructor(public readonly injector: Injector) {\n super();\n }\n\n ngOnChanges(simpleChange: SimpleChanges) {\n super.ngOnChanges(simpleChange);\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 @HostBinding('class') get hostClasses(): string {\n if (typeof this._rootClass === 'string') {\n return this._rootClass;\n }\n if (Array.isArray(this._rootClass)) {\n return this._rootClass.join(' ');\n }\n if (typeof this._rootClass === 'object') {\n return Object.keys(this._rootClass)\n .filter((key) => this._rootClass[key])\n .join(' ');\n }\n return '';\n }\n\n ngOnInit() {\n super.ngOnInit();\n this.ngControl = this.injector.get(NgControl, null, { optional: true });\n\n this.constructParser();\n\n this.initialized = true;\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 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 ?? undefined,\n maximumFractionDigits: 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, {\n style: 'currency',\n currency: this.currency,\n currencyDisplay: this.currencyDisplay,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0\n });\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, {\n style: this.mode,\n currency: this.currency,\n currencyDisplay: this.currencyDisplay\n });\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, {\n style: this.mode,\n currency: this.currency,\n currencyDisplay: this.currencyDisplay,\n minimumFractionDigits: 0,\n maximumFractionDigits: 0\n });\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 { value, selectionStart, selectionEnd } = this.input.nativeElement;\n const newValue = this.parseValue(value + char);\n const newValueStr = newValue != null ? newValue.toString() : '';\n const selectedValue = value.substring(selectionStart, selectionEnd);\n const selectedValueParsed = this.parseValue(selectedValue);\n const selectedValueStr = selectedValueParsed != null ? selectedValueParsed.toString() : '';\n\n if (selectionStart !== selectionEnd && selectedValueStr.length > 0) {\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 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