Skip to content

Commit 40f506f

Browse files
v3: Allow hyphen character in regex pattern to use support queries as is (#13605)
This is the v3 equivalent of PR #13596 Matching for the hyphen character in the existing regex to use support queries as-is Resolves #13594 Tests (w/ updated): - ✅ `supports-[display:grid]:grid` - ✅ `supports-[transform-origin:5%_5%]:underline` - ✅ `supports-[not(foo:bar)]:underline` - ✅ `supports-[(foo:bar)or(bar:baz)]:underline` - ✅ `supports-[(foo:bar)and(bar:baz)]:underline` - ✅ `supports-[(foo:bar)_and_(bar:baz)]:grid` - ✅ `supports-[(foo:bar)_and_(bar:baz)_or(baz:qux)]:grid` - ✅ `supports-[container-type]:underline` - ✅ `supports-grid:underline` - ✅ `supports-[--test]:flex` - ✅ `supports-[selector(A_>_B)]:underline` - ✅ `supports-[font-format(opentype)]:grid` - ✅ `supports-[font-tech(color-COLRv1)]:flex` --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent 4f9f603 commit 40f506f

File tree

3 files changed

+75
-35
lines changed

3 files changed

+75
-35
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
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+
- Improve support for raw `supports-[…]` queries in arbitrary values ([#13605](https://github.com/tailwindlabs/tailwindcss/pull/13605))
1113

1214
## [3.4.17] - 2024-12-17
1315

src/corePlugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ export let variantPlugins = {
409409
matchVariant(
410410
'supports',
411411
(value = '') => {
412-
let check = normalize(value)
413-
let isRaw = /^\w*\s*\(/.test(check)
412+
let check = value.startsWith('--') ? value : normalize(value)
413+
let isRaw = /^[\w-]*\s*\(/.test(check)
414414

415415
// Chrome has a bug where `(condition1)or(condition2)` is not valid
416416
// But `(condition1) or (condition2)` is supported.

tests/arbitrary-variants.test.js

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -767,18 +767,28 @@ it('should support supports', () => {
767767
<div class="supports-[display:grid]:grid"></div>
768768
<!-- Value with spaces, needs to be normalized -->
769769
<div class="supports-[transform-origin:5%_5%]:underline"></div>
770-
<!-- Selectors (raw) -->
771-
<div class="supports-[selector(A_>_B)]:underline"></div>
772770
<!-- 'not' check (raw) -->
773771
<div class="supports-[not(foo:bar)]:underline"></div>
774772
<!-- 'or' check (raw) -->
775773
<div class="supports-[(foo:bar)or(bar:baz)]:underline"></div>
776774
<!-- 'and' check (raw) -->
777775
<div class="supports-[(foo:bar)and(bar:baz)]:underline"></div>
776+
<!-- 'and' check with spaces (raw) -->
777+
<div class="supports-[(foo:bar)_and_(bar:baz)]:grid"></div>
778+
<!-- 'and' + 'or' check (raw) -->
779+
<div class="supports-[(foo:bar)_and_(bar:baz)_or(baz:qux)]:grid"></div>
778780
<!-- No value give for the property, defaulting to prop: var(--tw) -->
779781
<div class="supports-[container-type]:underline"></div>
780782
<!-- Named supports usage -->
781783
<div class="supports-grid:underline"></div>
784+
<!-- Custom properties -->
785+
<div class="supports-[--test]:flex"></div>
786+
<!-- Function syntax: selector (raw) -->
787+
<div class="supports-[selector(A_>_B)]:underline"></div>
788+
<!-- Function syntax: font-format (raw) -->
789+
<div class="supports-[font-format(opentype)]:grid"></div>
790+
<!-- Function syntax: font-tech (raw) -->
791+
<div class="supports-[font-tech(color-COLRv1)]:flex"></div>
782792
</div>
783793
`,
784794
},
@@ -791,45 +801,73 @@ it('should support supports', () => {
791801
`
792802

793803
return run(input, config).then((result) => {
794-
expect(result.css).toMatchFormattedCss(css`
795-
@supports (display: grid) {
796-
.supports-grid\:underline {
797-
text-decoration-line: underline;
798-
}
799-
.supports-\[display\:grid\]\:grid {
800-
display: grid;
801-
}
804+
expect(result.css).toMatchInlineSnapshot(`
805+
"@supports (display: grid) {
806+
.supports-grid\\:underline {
807+
text-decoration-line: underline
808+
}
802809
}
803-
@supports (foo: bar) and (bar: baz) {
804-
.supports-\[\(foo\:bar\)and\(bar\:baz\)\]\:underline {
805-
text-decoration-line: underline;
806-
}
810+
@supports (--test: var(--tw)) {
811+
.supports-\\[--test\\]\\:flex {
812+
display: flex
813+
}
807814
}
808-
@supports (foo: bar) or (bar: baz) {
809-
.supports-\[\(foo\:bar\)or\(bar\:baz\)\]\:underline {
810-
text-decoration-line: underline;
811-
}
815+
@supports font-tech(color-COLRv1) {
816+
.supports-\\[font-tech\\(color-COLRv1\\)\\]\\:flex {
817+
display: flex
818+
}
819+
}
820+
@supports (foo:bar) and (bar:baz) {
821+
.supports-\\[\\(foo\\:bar\\)_and_\\(bar\\:baz\\)\\]\\:grid {
822+
display: grid
823+
}
824+
}
825+
@supports (foo:bar) and (bar:baz) or (baz:qux) {
826+
.supports-\\[\\(foo\\:bar\\)_and_\\(bar\\:baz\\)_or\\(baz\\:qux\\)\\]\\:grid {
827+
display: grid
828+
}
829+
}
830+
@supports (display:grid) {
831+
.supports-\\[display\\:grid\\]\\:grid {
832+
display: grid
833+
}
834+
}
835+
@supports font-format(opentype) {
836+
.supports-\\[font-format\\(opentype\\)\\]\\:grid {
837+
display: grid
838+
}
839+
}
840+
@supports (foo:bar) and (bar:baz) {
841+
.supports-\\[\\(foo\\:bar\\)and\\(bar\\:baz\\)\\]\\:underline {
842+
text-decoration-line: underline
843+
}
844+
}
845+
@supports (foo:bar) or (bar:baz) {
846+
.supports-\\[\\(foo\\:bar\\)or\\(bar\\:baz\\)\\]\\:underline {
847+
text-decoration-line: underline
848+
}
812849
}
813850
@supports (container-type: var(--tw)) {
814-
.supports-\[container-type\]\:underline {
815-
text-decoration-line: underline;
816-
}
851+
.supports-\\[container-type\\]\\:underline {
852+
text-decoration-line: underline
853+
}
817854
}
818-
@supports not (foo: bar) {
819-
.supports-\[not\(foo\:bar\)\]\:underline {
820-
text-decoration-line: underline;
821-
}
855+
@supports not (foo:bar) {
856+
.supports-\\[not\\(foo\\:bar\\)\\]\\:underline {
857+
text-decoration-line: underline
858+
}
822859
}
823860
@supports selector(A > B) {
824-
.supports-\[selector\(A_\>_B\)\]\:underline {
825-
text-decoration-line: underline;
826-
}
861+
.supports-\\[selector\\(A_\\>_B\\)\\]\\:underline {
862+
text-decoration-line: underline
863+
}
827864
}
828-
@supports (transform-origin: 5% 5%) {
829-
.supports-\[transform-origin\:5\%_5\%\]\:underline {
830-
text-decoration-line: underline;
831-
}
865+
@supports (transform-origin:5% 5%) {
866+
.supports-\\[transform-origin\\:5\\%_5\\%\\]\\:underline {
867+
text-decoration-line: underline
868+
}
832869
}
870+
"
833871
`)
834872
})
835873
})

0 commit comments

Comments
 (0)