Skip to content

Commit 595b88f

Browse files
Support bare col-* and row-* utilities (#15183)
Resolves #15170. This PR adds support for bare integer values to the `col-*` and `row-*` utilities: ```css .col-5 { grid-column: 5; } .row-6 { grid-row: 6; } ``` These properties are shorthands for `grid-column-start`/`grid-column-end` and `grid-row-start`/`grid-row-end`, so using a bare integer value ends up being a shortcut for: ```css .col-5 { grid-column-start: 5; grid-column-end: auto; } ``` …which makes these basically work like an alternative to `col-start-*` and `row-start-*`. These support negative values like `-col-6` as well, which also technically extends to arbitrary values like `-col-[6/span_2]` now even though that is a junk value. I've decided not to guard against that though and just consider it user error to keep the implementation simple. --------- Co-authored-by: Adam Wathan <[email protected]> Co-authored-by: Philipp Spiess <[email protected]>
1 parent 66ef77c commit 595b88f

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- _Experimental_: Add `scripting`, `scripting-none`, and `scripting-initial` variants ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
1515
- _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370))
1616
- _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
17+
- Add `col-<number>` and `row-<number>` utilities for `grid-column` and `grid-row` ([#15183](https://github.com/tailwindlabs/tailwindcss/pull/15183))
1718

1819
### Fixed
1920

packages/tailwindcss/src/utilities.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,8 @@ test('order', async () => {
10861086
test('col', async () => {
10871087
expect(
10881088
await run([
1089+
'col-11',
1090+
'-col-12',
10891091
'col-auto',
10901092
'col-span-4',
10911093
'col-span-17',
@@ -1094,7 +1096,15 @@ test('col', async () => {
10941096
'col-span-[var(--my-variable)]',
10951097
]),
10961098
).toMatchInlineSnapshot(`
1097-
".col-\\[span_123\\/span_123\\] {
1099+
".-col-12 {
1100+
grid-column: calc(12 * -1);
1101+
}
1102+
1103+
.col-11 {
1104+
grid-column: 11;
1105+
}
1106+
1107+
.col-\\[span_123\\/span_123\\] {
10981108
grid-column: span 123 / span 123;
10991109
}
11001110
@@ -1213,6 +1223,8 @@ test('col-end', async () => {
12131223
test('row', async () => {
12141224
expect(
12151225
await run([
1226+
'row-11',
1227+
'-row-12',
12161228
'row-auto',
12171229
'row-span-4',
12181230
'row-span-17',
@@ -1221,7 +1233,15 @@ test('row', async () => {
12211233
'row-span-[var(--my-variable)]',
12221234
]),
12231235
).toMatchInlineSnapshot(`
1224-
".row-\\[span_123\\/span_123\\] {
1236+
".-row-12 {
1237+
grid-row: calc(12 * -1);
1238+
}
1239+
1240+
.row-11 {
1241+
grid-row: 11;
1242+
}
1243+
1244+
.row-\\[span_123\\/span_123\\] {
12251245
grid-row: span 123 / span 123;
12261246
}
12271247

packages/tailwindcss/src/utilities.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ export function createUtilities(theme: Theme) {
651651
*/
652652
staticUtility('col-auto', [['grid-column', 'auto']])
653653
functionalUtility('col', {
654+
supportsNegative: true,
655+
handleBareValue: ({ value }) => {
656+
if (!isPositiveInteger(value)) return null
657+
return value
658+
},
654659
themeKeys: ['--grid-column'],
655660
handle: (value) => [decl('grid-column', value)],
656661
})
@@ -719,6 +724,11 @@ export function createUtilities(theme: Theme) {
719724
*/
720725
staticUtility('row-auto', [['grid-row', 'auto']])
721726
functionalUtility('row', {
727+
supportsNegative: true,
728+
handleBareValue: ({ value }) => {
729+
if (!isPositiveInteger(value)) return null
730+
return value
731+
},
722732
themeKeys: ['--grid-row'],
723733
handle: (value) => [decl('grid-row', value)],
724734
})

0 commit comments

Comments
 (0)