Skip to content

fix(input-number): avoid redundant calculation #18119

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion packages/primeng/src/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const INPUTNUMBER_VALUE_ACCESSOR: any = {
useExisting: forwardRef(() => InputNumber),
multi: true
};

/**
* InputNumber is an input component to provide numerical input.
* @group Components
Expand Down Expand Up @@ -402,20 +403,23 @@ export class InputNumber extends BaseComponent implements OnInit, AfterContentIn
* @group Props
*/
@Input({ transform: booleanAttribute }) autofocus: boolean | undefined;

/**
* When present, it specifies that the element should be disabled.
* @group Props
*/
@Input() get disabled(): boolean | undefined {
return this._disabled;
}

set disabled(disabled: boolean | undefined) {
if (disabled) this.focused = false;

this._disabled = disabled;

if (this.timer) this.clearTimer();
}

/**
* Spans 100% width of the container when enabled.
* @group Props
Expand Down Expand Up @@ -639,6 +643,7 @@ export class InputNumber extends BaseComponent implements OnInit, AfterContentIn
const decimalChar = this.getDecimalChar();
return new RegExp(`[${decimalChar}]`, 'g');
}

getDecimalChar(): string {
const formatter = new Intl.NumberFormat(this.locale, { ...this.getOptions(), useGrouping: false });
return formatter
Expand Down Expand Up @@ -1516,7 +1521,7 @@ export class InputNumber extends BaseComponent implements OnInit, AfterContentIn
writeValue(value: any): void {
this.value = value ? Number(value) : value;
if (this.input) {
this.input.nativeElement.value = value ? Number(value) : value;
this.input.nativeElement.value = this.value ? String(this.value) : null;
}
this.cd.markForCheck();
}
Expand Down
Loading