Skip to content

Commit fd9dbe1

Browse files
authored
Allow the use of @media print without parens (#5898)
1 parent 5058275 commit fd9dbe1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/lib/setupContextUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
230230
return ({ format }) => format(str)
231231
}
232232

233-
let [, name, params] = /@(.*?) (\(.*\))/g.exec(str)
233+
let [, name, params] = /@(.*?) (.*)/g.exec(str)
234234
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
235235
})
236236
.reverse()

tests/variants.test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ it('should properly handle keyframes with multiple variants', async () => {
239239
`)
240240
})
241241

242+
test('custom addVariant with more complex media query params', () => {
243+
let config = {
244+
content: [
245+
{
246+
raw: html` <div class="magic:text-center"></div> `,
247+
},
248+
],
249+
plugins: [
250+
function ({ addVariant }) {
251+
addVariant('magic', '@media screen and (max-wdith: 600px)')
252+
},
253+
],
254+
}
255+
256+
return run('@tailwind components;@tailwind utilities', config).then((result) => {
257+
return expect(result.css).toMatchFormattedCss(css`
258+
@media screen and (max-wdith: 600px) {
259+
.magic\:text-center {
260+
text-align: center;
261+
}
262+
}
263+
`)
264+
})
265+
})
266+
242267
test('custom addVariant with nested media & format shorthand', () => {
243268
let config = {
244269
content: [
@@ -248,15 +273,15 @@ test('custom addVariant with nested media & format shorthand', () => {
248273
],
249274
plugins: [
250275
function ({ addVariant }) {
251-
addVariant('magic', '@supports (hover: hover) { @media (print) { &:disabled } }')
276+
addVariant('magic', '@supports (hover: hover) { @media print { &:disabled } }')
252277
},
253278
],
254279
}
255280

256281
return run('@tailwind components;@tailwind utilities', config).then((result) => {
257282
return expect(result.css).toMatchFormattedCss(css`
258283
@supports (hover: hover) {
259-
@media (print) {
284+
@media print {
260285
.magic\:text-center:disabled {
261286
text-align: center;
262287
}

0 commit comments

Comments
 (0)