Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacing: fix resolver for empty strings, and strings with spaces #6078

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading