Skip to content

Commit

Permalink
Fix: Preserve spaces when mask is invalid or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh committed Mar 19, 2018
1 parent be75bd4 commit cb97b02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/components/TextField/Mask.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Mask.propTypes = {
*/
export function unmask(value, mask) {
if (!value || typeof value !== 'string') return value;

const rawValue = value;
value = value.trim();

if (mask === 'currency') {
Expand All @@ -223,6 +223,8 @@ export function unmask(value, mask) {
} else if (Object.keys(deliminatedMaskRegex).includes(mask)) {
// Remove the deliminators and revert to single ungrouped string
value = toInt(value);
} else {
return rawValue;
}

return value;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/TextField/Mask.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('Mask', function() {

describe('unmask', () => {
it('returns value when mask is undefined', () => {
expect(unmask('1,234')).toBe('1,234');
expect(unmask(' 1,234 Foo ')).toBe(' 1,234 Foo ');
});

it('returns value when mask is unknown', () => {
Expand Down

0 comments on commit cb97b02

Please sign in to comment.