Skip to content

Commit

Permalink
[@mantine/core] Fix 2xl and other similar values being treated as C…
Browse files Browse the repository at this point in the history
…SS value instead of theme value (#6855)
  • Loading branch information
Kenzo-Wada authored Sep 25, 2024
1 parent f1f9cf0 commit 8fb3297
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ describe('@mantine/core/isNumberLike', () => {
expect(isNumberLike('a')).toBe(false);
expect(isNumberLike('a1')).toBe(false);
});

it('returns false for custom sizes', () => {
expect(isNumberLike('2xl')).toBe(false);
expect(isNumberLike('3xl')).toBe(false);
expect(isNumberLike('2xs')).toBe(false);
expect(isNumberLike('3xs')).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function isNumberLike(value: unknown) {
return true;
}

return /[0-9]/.test(value.trim().replace('-', '')[0]);
const cssUnitsRegex =
/^[+-]?[0-9]+(\.[0-9]+)?(px|em|rem|ex|ch|lh|rlh|vw|vh|vmin|vmax|vb|vi|svw|svh|lvw|lvh|dvw|dvh|cm|mm|in|pt|pc|q|%)?$/;
const values = value.trim().split(/\s+/);
return values.every((val) => cssUnitsRegex.test(val));
}

return false;
Expand Down

0 comments on commit 8fb3297

Please sign in to comment.