From ad114db07124cdbbeb495066faadb2ed7945ffa6 Mon Sep 17 00:00:00 2001 From: Sawyer Hollenshead Date: Fri, 9 Mar 2018 10:42:40 -0500 Subject: [PATCH] Accept negative currency masked values (#254) --- packages/core/src/components/TextField/Mask.jsx | 2 +- packages/core/src/components/TextField/Mask.test.jsx | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/src/components/TextField/Mask.jsx b/packages/core/src/components/TextField/Mask.jsx index c9ee9b3dd4..602d13bd12 100644 --- a/packages/core/src/components/TextField/Mask.jsx +++ b/packages/core/src/components/TextField/Mask.jsx @@ -31,7 +31,7 @@ export class Mask extends React.PureComponent { // 0 = number, 1 = decimals const parts = value.split('.'); - const digitsRegex = /\d/g; + const digitsRegex = /^-|\d/g; // include a check for a beginning "-" for negative numbers const a = parts[0].match(digitsRegex).join(''); const b = parts.length >= 2 && parts[1].match(digitsRegex).join(''); diff --git a/packages/core/src/components/TextField/Mask.test.jsx b/packages/core/src/components/TextField/Mask.test.jsx index 892c27e0b0..460993ba04 100644 --- a/packages/core/src/components/TextField/Mask.test.jsx +++ b/packages/core/src/components/TextField/Mask.test.jsx @@ -114,5 +114,12 @@ describe('Mask', function() { expect(input.prop('value')).toBe('12,345,678.90'); }); + + it('accepts negative values', () => { + const data = render({ mask: 'currency' }, { value: '-1,234' }); + const input = data.wrapper.find('input'); + + expect(input.prop('value')).toBe('-1,234'); + }); }); });