Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of @media print without parens #5898

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
allow the use of @media print without parens
  • Loading branch information
RobinMalfait committed Oct 27, 2021
commit b35c475ec50936bc035596159007fbf1f823e142
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