fix: editing negative numbers (#2538)

* fix: editing negative numbers

* fix: editing negative numbers (changeset added)
This commit is contained in:
Bilal Özlü 2025-07-17 15:20:26 +03:00 committed by GitHub
parent fff91b4d11
commit 9a4a8735b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': minor
---
Editing negative numbers in LionInputAmount become possible both with '-' and '\u2212'

View file

@ -31,7 +31,7 @@ function round(value, decimals) {
* @param {FormatNumberOptions} [givenOptions] Locale Options
*/
export function parseAmount(value, givenOptions) {
const unmatchedInput = value.match(/[^0-9,.\- ]/g);
const unmatchedInput = value.match(/[^0-9,.\-\u2212 ]/g);
// for the full paste behavior documentation:
// ./docs/components/input-amount/use-cases.md#paste-behavior
if (unmatchedInput && givenOptions?.mode !== 'pasted') {

View file

@ -71,4 +71,9 @@ describe('parseAmount()', async () => {
parseAmount('123.456,78', { mode: 'user-edited', viewValueStates: ['formatted'] }),
).to.equal(123456.78);
});
it('parses negative numbers', async () => {
expect(parseAmount('15.00')).to.equal(-15);
expect(parseAmount('-333.33')).to.equal(-333.33);
});
});