From 9a4a8735b0843e137775cc8d14ea07dcbc7946d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilal=20=C3=96zl=C3=BC?= <37140763+bilalozlu@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:20:26 +0300 Subject: [PATCH] fix: editing negative numbers (#2538) * fix: editing negative numbers * fix: editing negative numbers (changeset added) --- .changeset/hot-games-press.md | 5 +++++ packages/ui/components/input-amount/src/parsers.js | 2 +- packages/ui/components/input-amount/test/parsers.test.js | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/hot-games-press.md diff --git a/.changeset/hot-games-press.md b/.changeset/hot-games-press.md new file mode 100644 index 000000000..e3b0933fc --- /dev/null +++ b/.changeset/hot-games-press.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': minor +--- + +Editing negative numbers in LionInputAmount become possible both with '-' and '\u2212' diff --git a/packages/ui/components/input-amount/src/parsers.js b/packages/ui/components/input-amount/src/parsers.js index 4ed7ea65f..00164365f 100644 --- a/packages/ui/components/input-amount/src/parsers.js +++ b/packages/ui/components/input-amount/src/parsers.js @@ -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') { diff --git a/packages/ui/components/input-amount/test/parsers.test.js b/packages/ui/components/input-amount/test/parsers.test.js index 0d942f8ee..d8b693631 100644 --- a/packages/ui/components/input-amount/test/parsers.test.js +++ b/packages/ui/components/input-amount/test/parsers.test.js @@ -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); + }); });