Skip to content

[css-mediaqueries-5] How to handle media query lists in @custom-media rules #5458

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

Closed
stephen opened this issue Aug 21, 2020 · 1 comment
Closed

Comments

@stephen
Copy link

stephen commented Aug 21, 2020

In media queries level 5, custom media queries are allowed to specify a list.

As an example, how should this stylesheet get handled?

/* --modern targets modern devices that support color or hover */
@custom-media --modern (color), (hover);

@media (--modern) and (width > 1024px) {
  .a { color: green; }
}

My initial guess was that user agents should do a dot product of sorts and produce rules for @media (color) and (width > 1024px), (hover) and (width > 1024px) { ... }. This feels to me like a reasonable (albeit somewhat tricky to parse) interpretation of the stylesheet authors intent.

However, looking at the existing postcss-custom-media implementation, the produced media query is: @media (color), (hover) and (width > 1024px) { ... }. This at least felt surprising to me - it's not clear to me why you'd try to write a custom media query with multiple media queries in the list.

If this is the intended behavior, If It'd be helpful to hear if there is a compelling use case for this kind of direct interpolation.

If it's not an intended behavior, I wonder if it'd be clearer for stylesheet authors if @custom-media only allowed a single media query production rather than a list of media queries.


tl; dr: should @custom-media only take a single media query instead of a list?

@tabatkins
Copy link
Member

Yeah, I should change it to take only a single MQ, since authors can just use or for that, and I don't really see a need for media types since we still only have the two ("screen" and "print").

That PostCSS implementation is clearly busted; it's just doing textual substitution, and is producing something whose semantics are clearly different from what the source indicated.

stephen added a commit to stephen/cssc that referenced this issue Aug 22, 2020
From w3c/csswg-drafts#5458 (comment),
it seems that it's unintended that @Custom-Media allows multiple
media queries. Instead, we take only one.

I added a test for the case where multiple are returned, but the
error message is unsatisfying - it complains about wanting
a selector (because custom media at rule parsing is done and
we want to move on to parsing a qualified rule), but it
isn't helpful for someone who is confused about the at rule.
stephen added a commit to stephen/cssc that referenced this issue Aug 22, 2020
From w3c/csswg-drafts#5458 (comment),
it seems that it's unintended that @Custom-Media allows multiple
media queries. Instead, we take only one.

I added a test for the case where multiple are returned, but the
error message is unsatisfying - it complains about wanting
a selector (because custom media at rule parsing is done and
we want to move on to parsing a qualified rule), but it
isn't helpful for someone who is confused about the at rule.
frivoal added a commit that referenced this issue Dec 18, 2021
This helps lift the confusion that prompted #5458
@frivoal frivoal closed this as completed Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants