Skip to content

Commit

Permalink
Accept negative currency masked values (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh authored Mar 9, 2018
1 parent 3e3f8fc commit ad114db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/components/TextField/Mask.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('');

Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/components/TextField/Mask.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit ad114db

Please sign in to comment.