Skip to content

Commit

Permalink
[@mantine/core] Fix incorrect empty string handling in style props (#…
Browse files Browse the repository at this point in the history
…6078)

* Spacing: fix resolver for empty strings, and strings with spaces

* fix a test that was broken with corrected output from this change
  • Loading branch information
s-cork committed Apr 23, 2024
1 parent a1c7ff4 commit 9130628
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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)}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('@mantine/units-converters/rem', () => {

it('correctly transforms a list of coma separated values', () => {
expect(rem('0 0, 0 4px, 4px -4px, -4px 0')).toBe(
'0rem 0rem,0rem 0rem calc(0.25rem * var(--mantine-scale)),0rem calc(0.25rem * var(--mantine-scale)) calc(-0.25rem * var(--mantine-scale)),0rem calc(-0.25rem * var(--mantine-scale)) 0rem'
'0rem 0rem, 0rem calc(0.25rem * var(--mantine-scale)), calc(0.25rem * var(--mantine-scale)) calc(-0.25rem * var(--mantine-scale)), calc(-0.25rem * var(--mantine-scale)) 0rem'
);
});
});
Expand Down
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 9130628

Please sign in to comment.