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

feat(inputnumber): add anyDecimalKey option #16992

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
8 changes: 7 additions & 1 deletion packages/primeng/src/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ export class InputNumber extends BaseComponent implements OnInit, AfterContentIn
* @group Props
*/
@Input() mode: string | any = 'decimal';
/**
* Determines whether any decimal key on the keyboard can be used for adding decimals.
* @group Props
*/
@Input({ transform: booleanAttribute }) anyDecimalKey: boolean = false;
/**
* 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.
* @group Props
Expand Down Expand Up @@ -1042,11 +1047,12 @@ export class InputNumber extends BaseComponent implements OnInit, AfterContentIn
let char = String.fromCharCode(code);
let isDecimalSign = this.isDecimalSign(char);
const isMinusSign = this.isMinusSign(char);
const isAnyDecimalKey = event.code === 'NumpadDecimal' || (this.anyDecimalKey && (event.code === 'Comma' || event.code === 'Period'));

if (code != 13) {
event.preventDefault();
}
if (!isDecimalSign && event.code === 'NumpadDecimal') {
if (!isDecimalSign && isAnyDecimalKey) {
isDecimalSign = true;
char = this._decimalChar;
code = char.charCodeAt(0);
Expand Down