Skip to content

Commit

Permalink
Allow the use of @media print without parens (#5898)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Oct 27, 2021
1 parent 5058275 commit fd9dbe1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
return ({ format }) => format(str)
}

let [, name, params] = /@(.*?) (\(.*\))/g.exec(str)
let [, name, params] = /@(.*?) (.*)/g.exec(str)
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
})
.reverse()
Expand Down
29 changes: 27 additions & 2 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,31 @@ it('should properly handle keyframes with multiple variants', async () => {
`)
})

test('custom addVariant with more complex media query params', () => {
let config = {
content: [
{
raw: html` <div class="magic:text-center"></div> `,
},
],
plugins: [
function ({ addVariant }) {
addVariant('magic', '@media screen and (max-wdith: 600px)')
},
],
}

return run('@tailwind components;@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
@media screen and (max-wdith: 600px) {
.magic\:text-center {
text-align: center;
}
}
`)
})
})

test('custom addVariant with nested media & format shorthand', () => {
let config = {
content: [
Expand All @@ -248,15 +273,15 @@ test('custom addVariant with nested media & format shorthand', () => {
],
plugins: [
function ({ addVariant }) {
addVariant('magic', '@supports (hover: hover) { @media (print) { &:disabled } }')
addVariant('magic', '@supports (hover: hover) { @media print { &:disabled } }')
},
],
}

return run('@tailwind components;@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
@supports (hover: hover) {
@media (print) {
@media print {
.magic\:text-center:disabled {
text-align: center;
}
Expand Down

0 comments on commit fd9dbe1

Please sign in to comment.