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

[css-conditional-5] Add container() as a leaf of the @when rule #6917

Open
bramus opened this issue Dec 28, 2021 · 5 comments
Open

[css-conditional-5] Add container() as a leaf of the @when rule #6917

bramus opened this issue Dec 28, 2021 · 5 comments

Comments

@bramus
Copy link
Contributor

bramus commented Dec 28, 2021

It would be nice to also see a container() function as a leaf of the @when rule, in addition to the already specced media() and supports() functions.

The syntax would preferably be the same as the @​container rule:

container() = container( [ <container-name> | [ name(<container-name>) || type(<container-type>+) ] ]? <container-query> )

(Perhaps the optional part should not be optional here, for performance reasons? 🤔)

Use case: it would allow stuff such as easy dark mode toggling based on the value of a custom property on a style container:

@when media(prefers-color-scheme: dark) or container(root style(--color-scheme = dark)) {
  body {
    --primary-color: #efefef;
    --primary-bg-color: #333;
  }
}
@andruud
Copy link
Member

andruud commented Jan 5, 2022

This requires that @when has @container-style handling of inner (name-defining) at-rules. In other words, inner at-rules would apply regardless of the condition.

@tabatkins
Copy link
Member

Yeah, @container just plain works differently from all the other conditional rules. I don't think it can be usefully merged in, unfortunately.

@mirisuzanne
Copy link
Contributor

I think conceptually the @when rule is syntax sugar for things we can already do. It's already possible to combine media, supports, and container queries by nesting. It seems to me that the behavior here would only have to match the existing behavior of those rules when combined?

This would also make #6917 possible without any special container syntax. That seems to me like exactly the underlying problem that @when is designed to solve - nesting can be clunky, and OR combinations are repetitive. I would very much like to make this work if we can.

@andruud
Copy link
Member

andruud commented Feb 9, 2022

It doesn't seem impossible provided we have a workable solution for inner at-rules. Using @layer as an example:

@media(a) { @layer x; } -> affects layer order only when a is true.
@container(b) { @layer x; } -> affects layer order regardless of b.
@when media(a) or container(b) { @layer x; } -> ???

@tabatkins
Copy link
Member

Right, I don't think that's a solveable problem. I'm strongly against the layer interpretation changing based on precisely what queries you use in a @when rule; that means something that should be a no-op (adding an or false-query() branch) might have knock-on effects.

Further, it's not just combining the known media/supports/container queries, but combining any query in the future, too - we can't predict what unknown-new-query(foo) will do to the semantics of layers and similar things, so we'll have to define a behavior and that has a chance of locking the behavior in when the query is widely supported. Right now we only have to deal with the truth value of an unknown query, which is much safer and more limited. (Tho even then we have to decide whether to use the 3-value boolean logic, like MQs, or 2-value, like SQs. Luckily, defaulting to 3-value at the top level is fine.)

@mirisuzanne mirisuzanne moved this from To do to Deferred in Container Queries [css-contain] Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-conditional-5 Current Work
Development

No branches or pull requests

4 participants