Skip to content
Closed
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
6 changes: 5 additions & 1 deletion packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,7 @@ test('aspect-ratio', async () => {
}
@tailwind utilities;
`,
['aspect-video', 'aspect-[10/9]', 'aspect-4/3'],
['aspect-video', 'aspect-[10/9]', 'aspect-4/3', 'aspect-8.5/11'],
),
).toMatchInlineSnapshot(`
":root, :host {
Expand All @@ -3167,6 +3167,10 @@ test('aspect-ratio', async () => {
aspect-ratio: 4 / 3;
}

.aspect-8\\.5\\/11 {
aspect-ratio: 8.5 / 11;
}

.aspect-\\[10\\/9\\] {
aspect-ratio: 10 / 9;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DefaultMap } from './utils/default-map'
import {
inferDataType,
isPositiveInteger,
isPositiveNumber,
isStrictPositiveInteger,
isValidOpacityValue,
isValidSpacingMultiplier,
Expand Down Expand Up @@ -981,7 +982,7 @@ export function createUtilities(theme: Theme) {
handleBareValue: ({ fraction }) => {
if (fraction === null) return null
let [lhs, rhs] = segment(fraction, '/')
if (!isPositiveInteger(lhs) || !isPositiveInteger(rhs)) return null
if (!isPositiveNumber(lhs) || !isPositiveNumber(rhs)) return null
return fraction
},
handle: (value) => [decl('aspect-ratio', value)],
Expand Down
5 changes: 5 additions & 0 deletions packages/tailwindcss/src/utils/infer-data-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ export function isStrictPositiveInteger(value: any) {
return Number.isInteger(num) && num > 0 && String(num) === String(value)
}

export function isPositiveNumber(value: any) {
let num = Number(value)
return Number.isFinite(num) && num > 0 && String(num) === String(value)
}

export function isValidSpacingMultiplier(value: any) {
return isMultipleOf(value, 0.25)
}
Expand Down