Skip to content

Commit f10454c

Browse files
committed
Support negative values for {col,row}-{start,end} utilities
1 parent 04906c8 commit f10454c

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

packages/tailwindcss/src/utilities.test.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,13 @@ test('col', () => {
701701
})
702702

703703
test('col-start', () => {
704-
expect(run(['col-start-auto', 'col-start-4', 'col-start-99', 'col-start-[123]']))
704+
expect(run(['col-start-auto', 'col-start-4', 'col-start-99', 'col-start-[123]', '-col-start-4']))
705705
.toMatchInlineSnapshot(`
706-
".col-start-4 {
706+
".-col-start-4 {
707+
grid-column-start: calc(4 * -1);
708+
}
709+
710+
.col-start-4 {
707711
grid-column-start: 4;
708712
}
709713
@@ -719,28 +723,33 @@ test('col-start', () => {
719723
grid-column-start: auto;
720724
}"
721725
`)
722-
expect(run(['col-start', '-col-start-4', 'col-start-unknown'])).toEqual('')
726+
expect(run(['col-start', 'col-start-unknown'])).toEqual('')
723727
})
724728

725729
test('col-end', () => {
726-
expect(run(['col-end-auto', 'col-end-4', 'col-end-99', 'col-end-[123]'])).toMatchInlineSnapshot(`
727-
".col-end-4 {
728-
grid-column-end: 4;
729-
}
730+
expect(run(['col-end-auto', 'col-end-4', 'col-end-99', 'col-end-[123]', '-col-end-4']))
731+
.toMatchInlineSnapshot(`
732+
".-col-end-4 {
733+
grid-column-end: calc(4 * -1);
734+
}
730735
731-
.col-end-99 {
732-
grid-column-end: 99;
733-
}
736+
.col-end-4 {
737+
grid-column-end: 4;
738+
}
734739
735-
.col-end-\\[123\\] {
736-
grid-column-end: 123;
737-
}
740+
.col-end-99 {
741+
grid-column-end: 99;
742+
}
738743
739-
.col-end-auto {
740-
grid-column-end: auto;
741-
}"
742-
`)
743-
expect(run(['col-end', '-col-end-4', 'col-end-unknown'])).toEqual('')
744+
.col-end-\\[123\\] {
745+
grid-column-end: 123;
746+
}
747+
748+
.col-end-auto {
749+
grid-column-end: auto;
750+
}"
751+
`)
752+
expect(run(['col-end', 'col-end-unknown'])).toEqual('')
744753
})
745754

746755
test('row', () => {
@@ -782,7 +791,7 @@ test('row', () => {
782791
})
783792

784793
test('row-start', () => {
785-
expect(run(['row-start-auto', 'row-start-4', 'row-start-99', 'row-start-[123]']))
794+
expect(run(['row-start-auto', 'row-start-4', 'row-start-99', 'row-start-[123]', '-row-start-4']))
786795
.toMatchInlineSnapshot(`
787796
".row-start-4 {
788797
grid-row-start: 4;
@@ -800,11 +809,12 @@ test('row-start', () => {
800809
grid-row-start: auto;
801810
}"
802811
`)
803-
expect(run(['row-start', '-row-start-4', 'row-start-unknown'])).toEqual('')
812+
expect(run(['row-start', 'row-start-unknown'])).toEqual('')
804813
})
805814

806815
test('row-end', () => {
807-
expect(run(['row-end-auto', 'row-end-4', 'row-end-99', 'row-end-[123]'])).toMatchInlineSnapshot(`
816+
expect(run(['row-end-auto', 'row-end-4', 'row-end-99', 'row-end-[123]', '-row-end-4']))
817+
.toMatchInlineSnapshot(`
808818
".row-end-4 {
809819
grid-row-end: 4;
810820
}
@@ -821,7 +831,7 @@ test('row-end', () => {
821831
grid-row-end: auto;
822832
}"
823833
`)
824-
expect(run(['row-end', '-row-end-4', 'row-end-unknown'])).toEqual('')
834+
expect(run(['row-end', 'row-end-unknown'])).toEqual('')
825835
})
826836

827837
test('float', () => {

packages/tailwindcss/src/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ export function createUtilities(theme: Theme) {
653653
*/
654654
staticUtility('col-start-auto', [['grid-column-start', 'auto']])
655655
functionalUtility('col-start', {
656+
supportsNegative: true,
656657
handleBareValue: ({ value }) => {
657658
if (!Number.isInteger(Number(value))) return null
658659
return value
@@ -666,6 +667,7 @@ export function createUtilities(theme: Theme) {
666667
*/
667668
staticUtility('col-end-auto', [['grid-column-end', 'auto']])
668669
functionalUtility('col-end', {
670+
supportsNegative: true,
669671
handleBareValue: ({ value }) => {
670672
if (!Number.isInteger(Number(value))) return null
671673
return value
@@ -683,13 +685,15 @@ export function createUtilities(theme: Theme) {
683685

684686
suggest('col-start', () => [
685687
{
688+
supportsNegative: true,
686689
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
687690
valueThemeKeys: ['--grid-column-start'],
688691
},
689692
])
690693

691694
suggest('col-end', () => [
692695
{
696+
supportsNegative: true,
693697
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
694698
valueThemeKeys: ['--grid-column-end'],
695699
},
@@ -718,6 +722,7 @@ export function createUtilities(theme: Theme) {
718722
*/
719723
staticUtility('row-start-auto', [['grid-row-start', 'auto']])
720724
functionalUtility('row-start', {
725+
supportsNegative: true,
721726
handleBareValue: ({ value }) => {
722727
if (!Number.isInteger(Number(value))) return null
723728
return value
@@ -731,6 +736,7 @@ export function createUtilities(theme: Theme) {
731736
*/
732737
staticUtility('row-end-auto', [['grid-row-end', 'auto']])
733738
functionalUtility('row-end', {
739+
supportsNegative: true,
734740
handleBareValue: ({ value }) => {
735741
if (!Number.isInteger(Number(value))) return null
736742
return value
@@ -748,13 +754,15 @@ export function createUtilities(theme: Theme) {
748754

749755
suggest('row-start', () => [
750756
{
757+
supportsNegative: true,
751758
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
752759
valueThemeKeys: ['--grid-row-start'],
753760
},
754761
])
755762

756763
suggest('row-end', () => [
757764
{
765+
supportsNegative: true,
758766
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
759767
valueThemeKeys: ['--grid-row-end'],
760768
},

0 commit comments

Comments
 (0)