-
Notifications
You must be signed in to change notification settings - Fork 693
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-contain] Similar to window.matchMedia(), Container Queries should have a similar method #6205
Comments
Why isn't the existing ResizeObserver (as-is) good enough to listen for resize events on containers? |
The CSS Working Group just discussed
The full IRC log of that discussion<dael> Topic: Similar to window.matchMedia(), Container Queries should have a similar method<dael> github: /~https://github.com//issues/6205 <dael> miriam: Idea is have something similar for container queries. Claire (sp?) has provided a few options. Would be great to resolve on one. Or something else <dael> astearns: 3 options: new method. new observer. reuse resize observer <dael> fantasai: Possible use cases for both approaches. Could start with defining matchContainer since that's easy <dael> astearns: You're thinking we would need matchContainer and either new observer or reuse resize? <dael> fantasai: Yeah <dael> astearns: Anyone with opinions about adding matchContainer? <dael> TabAtkins: This would allow style queries in the matchContainer since they're under container query umbrella? <dael> fantasai: Yeah <dael> TabAtkins: Nice. Good <dael> astearns: Prop: Add a matchContainer method as proposed in issue. Keep issue open to decide if need new observer or if we can reuse the existing <dael> astearns: Objections? <dael> RESOLVED: Add a matchContainer method as proposed in issue. Keep issue open to decide if need new observer or if we can reuse the existing <fremy> FWIW I will not join the second call, I am going to bed, I think most issues I was involved in have been discussed already, or I left a comment with my thoughts. Talk to you all next week! |
Is there anything new about this? We created a Designer with CSS parsing support (/~https://github.com/node-projects/web-component-designer) where we would need the "matchContainer" API to find the mathcing container queries |
Wouldn't just checking a container element's offsetWidth when the window resizes be functionally the same as container query? |
no? container queries could not only check for a size.... |
I expected this to have already been implemented, such a shame. |
Just wanted to add that I ran into a use case where I wanted to be able to do;
Would have loved to be able to do this instead of writing some custom ResizeObserver which could potentially lead to performance issues if not managed mindful of re-paints for calculating/retrieving values. |
No movement on this yet? No offense but do we have to wait another 10 years for something as basic as this again? |
Some experimenting with learning about container-query changes via JS
|
Also stated here: https://www.w3.org/TR/css-contain-3/#the-csscontainerrule-interface |
I just ran into a case where I'd like to watch changes to a css variable using container style queries: const match = document.body.matchContainer( 'style( --theme: dark )' );
match.addEventListener( () => { /* .... */ } ); |
It would be good to get clarification on if this is intended to be in HTMLElement or Element? I would imagine Element so it works with SVG and MathML? Edit: the spec note itself says Elements but this issue and some of the browser issues say HTMLElement |
For sure it needs to be Element. Every Node wich is styleable via CSS and respects ContainerQueries should have this method. |
Why does it have to be on the element? |
i think the other similar APIs like matchMedia and matches are on the coresponding object, so this also should be. I think it the browser vendors should implement this in the near future. We have container queries but no API to check if a element matches... |
I was also surprised that there wasn't such api but that being said it can be very easily polyfilled using an invisible iframe in case you need this feature today: |
I created a polyfill for |
CSS Media Queries have a method on the Window interface (
window.matchMedia()
) giving a script the ability to listen for media query changes. I propose that CSS Container Queries has the same functionality. However, I think this introduces some complexity, and therefore I'd like to present two thoughts for consideration:Proposal 1
A new method on the
HTMLElement
interface possibly calledmatchContainer()
or something similar. Reason it wouldn't be on theWindow
is due to the nature of container queries - not being based upon viewport size, but size of the container. However, this should be influenced by the question still pending, which is what is the default behavior of a container query when there is nocontain
property on any parent element.Proposal 2
A new Observer of sorts, similar to
ResizeObserver
orMutationObserver
where it's a bit more clear that it is listening for any kind of container change, and that it relays the container as a member of aContainerQueryList
. This would make it not pollute theHTMLElement
interface, and instead be a DOM method. This would solely be used to identify when a container query is activated, and which items are affected by that activation.Admittedly, the second proposal seems very similar to what
ResizeObserver
does already, but I feel it misses the connection that CSS Contain Level 3 is attempting to solve. This could be something that might be added to ResizeObserver, but might also be its own API.Thoughts?
The text was updated successfully, but these errors were encountered: