Skip to content

Commit ea24995

Browse files
authored
Only generate positive grid-cols-* and grid-rows-* utilities (#16020)
This PR fixes an issue where `grid-cols-0` and `grid-rows-0` generated invalid CSS. We now ensure that the value is any positive integer (except 0). Fixes: #16012
1 parent 0655209 commit ea24995

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Only generate positive `grid-cols-*` and `grid-rows-*` utilities ([#16020](https://github.com/tailwindlabs/tailwindcss/pull/16020))
1113

1214
## [4.0.1] - 2025-01-29
1315

packages/tailwindcss/src/utilities.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6995,6 +6995,7 @@ test('grid-cols', async () => {
69956995
expect(
69966996
await run([
69976997
'grid-cols',
6998+
'grid-cols-0',
69986999
'-grid-cols-none',
69997000
'-grid-cols-subgrid',
70007001
'grid-cols--12',
@@ -7043,6 +7044,7 @@ test('grid-rows', async () => {
70437044
expect(
70447045
await run([
70457046
'grid-rows',
7047+
'grid-rows-0',
70467048
'-grid-rows-none',
70477049
'-grid-rows-subgrid',
70487050
'grid-rows--12',

packages/tailwindcss/src/utilities.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { DefaultMap } from './utils/default-map'
1717
import {
1818
inferDataType,
1919
isPositiveInteger,
20+
isStrictPositiveInteger,
2021
isValidOpacityValue,
2122
isValidSpacingMultiplier,
2223
} from './utils/infer-data-type'
@@ -1752,7 +1753,7 @@ export function createUtilities(theme: Theme) {
17521753
functionalUtility('grid-cols', {
17531754
themeKeys: ['--grid-template-columns'],
17541755
handleBareValue: ({ value }) => {
1755-
if (!isPositiveInteger(value)) return null
1756+
if (!isStrictPositiveInteger(value)) return null
17561757
return `repeat(${value}, minmax(0, 1fr))`
17571758
},
17581759
handle: (value) => [decl('grid-template-columns', value)],
@@ -1763,7 +1764,7 @@ export function createUtilities(theme: Theme) {
17631764
functionalUtility('grid-rows', {
17641765
themeKeys: ['--grid-template-rows'],
17651766
handleBareValue: ({ value }) => {
1766-
if (!isPositiveInteger(value)) return null
1767+
if (!isStrictPositiveInteger(value)) return null
17671768
return `repeat(${value}, minmax(0, 1fr))`
17681769
},
17691770
handle: (value) => [decl('grid-template-rows', value)],

packages/tailwindcss/src/utils/infer-data-type.ts

+5
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ export function isPositiveInteger(value: any) {
341341
return Number.isInteger(num) && num >= 0 && String(num) === String(value)
342342
}
343343

344+
export function isStrictPositiveInteger(value: any) {
345+
let num = Number(value)
346+
return Number.isInteger(num) && num > 0 && String(num) === String(value)
347+
}
348+
344349
export function isValidSpacingMultiplier(value: any) {
345350
return isMultipleOf(value, 0.25)
346351
}

0 commit comments

Comments
 (0)