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