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); + }); });