fix: editing negative numbers (#2538)
* fix: editing negative numbers * fix: editing negative numbers (changeset added)
This commit is contained in:
parent
fff91b4d11
commit
9a4a8735b0
3 changed files with 11 additions and 1 deletions
5
.changeset/hot-games-press.md
Normal file
5
.changeset/hot-games-press.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Editing negative numbers in LionInputAmount become possible both with '-' and '\u2212'
|
||||||
|
|
@ -31,7 +31,7 @@ function round(value, decimals) {
|
||||||
* @param {FormatNumberOptions} [givenOptions] Locale Options
|
* @param {FormatNumberOptions} [givenOptions] Locale Options
|
||||||
*/
|
*/
|
||||||
export function parseAmount(value, givenOptions) {
|
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:
|
// for the full paste behavior documentation:
|
||||||
// ./docs/components/input-amount/use-cases.md#paste-behavior
|
// ./docs/components/input-amount/use-cases.md#paste-behavior
|
||||||
if (unmatchedInput && givenOptions?.mode !== 'pasted') {
|
if (unmatchedInput && givenOptions?.mode !== 'pasted') {
|
||||||
|
|
|
||||||
|
|
@ -71,4 +71,9 @@ describe('parseAmount()', async () => {
|
||||||
parseAmount('123.456,78', { mode: 'user-edited', viewValueStates: ['formatted'] }),
|
parseAmount('123.456,78', { mode: 'user-edited', viewValueStates: ['formatted'] }),
|
||||||
).to.equal(123456.78);
|
).to.equal(123456.78);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses negative numbers', async () => {
|
||||||
|
expect(parseAmount('−15.00')).to.equal(-15);
|
||||||
|
expect(parseAmount('-333.33')).to.equal(-333.33);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue