Skip to content

Commit

Permalink
fix(number-field): handles values greater than 1000 (#4417)
Browse files Browse the repository at this point in the history
* fix(number-field): handles values greater than 1000

* chore(number-field): updated tests

---------

Co-authored-by: Rajdeep Chandra <rajdeepchandra@Rajdeeps-MacBook-Pro-2.local>
  • Loading branch information
blunteshwar and Rajdeep Chandra authored May 8, 2024
1 parent 3a57f89 commit 45d69d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/number-field/src/NumberField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ export class NumberField extends TextfieldBase {
: 0;
this._valueFormatter = new NumberFormatter(
this.languageResolver.language,
{ maximumFractionDigits: digitsAfterDecimal }
{
maximumFractionDigits: digitsAfterDecimal,
useGrouping: false,
}
);
}

Expand Down
26 changes: 26 additions & 0 deletions packages/number-field/test/number-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ describe('NumberField', () => {
expect(el.valueAsString).to.equal('-2.4');
expect(el.focusElement.value).to.equal('-2.4');
});
it('correctly handles max values greater than 1000 with step=1', async () => {
const el = await getElFrom(
Default({
step: 1,
min: 0,
max: 200000,
value: 999,
})
);

await clickBySelector(el, '.step-up');

expect(el.value).to.equal(1000);
expect(el.valueAsString).to.equal('1000');
expect(el.formattedValue).to.equal('1,000');
expect(el.focusElement.value).to.equal('1,000');

el.value = 15000;
await elementUpdated(el);

expect(el.value).to.equal(15000);
expect(el.valueAsString).to.equal('15000');
expect(el.formattedValue).to.equal('15,000');
expect(el.focusElement.value).to.equal('15,000');
});
});
describe('Increments', () => {
let el: NumberField;
Expand All @@ -164,6 +189,7 @@ describe('NumberField', () => {
expect(el.value).to.be.NaN;
expect(el.focusElement.value).to.equal('');
});

it('via pointer', async () => {
await clickBySelector(el, '.step-up');
expect(el.formattedValue).to.equal('0');
Expand Down

0 comments on commit 45d69d0

Please sign in to comment.