Skip to content

Commit

Permalink
Spacing: fix resolver for empty strings, and strings with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
s-cork committed Apr 13, 2024
1 parent afc9929 commit 7f6a176
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ describe('@mantine/core/Box/spacing-resolver', () => {
expect(spacingResolver('-10px', DEFAULT_THEME)).toBe(rem(-10));
expect(spacingResolver('1rem', DEFAULT_THEME)).toBe(rem('1rem'));
});

it('resolves empty strings correctly', () => {
expect(spacingResolver('', DEFAULT_THEME)).toBe(rem(''));
expect(spacingResolver(' 10px', DEFAULT_THEME)).toBe(` ${rem(10)}`);
});
});
5 changes: 5 additions & 0 deletions packages/@mantine/core/src/core/utils/units-converters/rem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function createConverter(units: string, { shouldScale = false } = {}) {
}

if (typeof value === 'string') {
// Number("") === 0 so exit early
if (value === '') {
return value;
}

if (value.startsWith('calc(') || value.startsWith('clamp(') || value.includes('rgba(')) {
return value;
}
Expand Down

0 comments on commit 7f6a176

Please sign in to comment.