fix: support decimal values in aspect ratio utilities#19669
fix: support decimal values in aspect ratio utilities#19669shtse8 wants to merge 1 commit intotailwindlabs:mainfrom
Conversation
Allow decimal numbers in aspect ratio bare values (e.g. `aspect-8.5/11`) by using `isPositiveNumber` instead of `isPositiveInteger` for validation. The CSS `aspect-ratio` property accepts any positive number, not just integers, so `aspect-ratio: 8.5 / 11` is valid CSS. Previously, `aspect-8.5/11` would silently produce no output because the decimal value failed the integer check. Fixes tailwindlabs#19663
WalkthroughThis change extends Tailwind CSS to support fractional aspect ratios in addition to integer ratios. A new utility function 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The
aspect-ratioutility only accepts integer values for bare fractions (e.g.aspect-4/3), but the CSSaspect-ratioproperty supports any positive number. Using a decimal likeaspect-8.5/11silently produces no output.Reported in #19663.
Solution
Added an
isPositiveNumberhelper (alongside the existingisPositiveInteger) that accepts finite non-negative numbers including decimals. Updated theaspectutility'shandleBareValueto useisPositiveNumberinstead ofisPositiveInteger.Before
After
Changes
packages/tailwindcss/src/utils/infer-data-type.ts— AddedisPositiveNumber()utility functionpackages/tailwindcss/src/utilities.ts— Changed aspect ratio validation fromisPositiveIntegertoisPositiveNumberpackages/tailwindcss/src/utilities.test.ts— Added test case foraspect-8.5/11Fixes #19663