-
Notifications
You must be signed in to change notification settings - Fork 783
[css-conditional-5] Add matchContainer() and ContainerQueryList API text
#13551
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
base: main
Are you sure you want to change the base?
Changes from all commits
21befc8
f12d2e2
49aa274
a85f92a
db2cf8d
71c3883
b5ded7a
2b174fa
84de73a
c0cdbf7
c4e9b83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1991,11 +1991,115 @@ The <code>CSSContainerRule</code> interface</h3> | |
| or simplification based on evaluating results) are not allowed. | ||
| </dl> | ||
|
|
||
| Issue(6205): Container Queries should have a <code>matchContainer</code> method. | ||
| This will be modeled on {{matchMedia()}} and the {{MediaQueryList}} interface, | ||
| but applied to Elements rather than the Window. | ||
| When measuring layout sizes, it behaves Similar to <code>resizeObserver</code>, | ||
| but it provides the additional Container Query syntax and features. | ||
| <h3 id=the-matchContainer-method>The matchContainer() method</h3> | ||
|
|
||
| <pre class=idl> | ||
| partial interface Element { | ||
| [NewObject] ContainerQueryList matchContainer(CSSOMString query); | ||
| }; | ||
| </pre> | ||
|
|
||
| The <dfn method for=PreferenceObject>matchContainer(query)</dfn> method, when invoked, must run these steps: | ||
|
|
||
| <ol> | ||
| <li>Let <var>parsed container query list</var> be the result of | ||
| <a lt='parse a container query list'>parsing</a> | ||
| <var>query</var>. | ||
| <li>Return a new {{ContainerQueryList}} object, | ||
| with [=this=] as the <a for=ContainerQueryList>element</a>, | ||
| as the <a for=ContainerQueryList>document</a>, | ||
| with <var>parsed container query list</var> | ||
| as its associated [=ContainerQueryList/container query list=]. | ||
| </ol> | ||
|
|
||
| <h3 id=the-ContainerQueryList-interface>The {{ContainerQueryList}} Interface</h3> | ||
|
|
||
| This section integrates with the <a for=/>event loop</a> defined in HTML. [[!HTML]] | ||
|
|
||
| A {{ContainerQueryList}} object has an associated | ||
| <dfn for=ContainerQueryList>container query list</dfn> | ||
| and an associated | ||
| <dfn for=ContainerQueryList>element</dfn> set(or assigned?) on creation. | ||
|
|
||
| A {{ContainerQueryList}} object has an associated | ||
| <dfn for=ContainerQueryList>container</dfn> which is the | ||
| <a lt='serialize a container query list'>serialized</a> | ||
| form of the associated [=ContainerQueryList/container query list=]. | ||
|
|
||
| A {{ContainerQueryList}} object has an associated | ||
| <dfn for=ContainerQueryList>matches state</dfn> | ||
| which is true if the associated [=ContainerQueryList/container query list=] | ||
| matches the state of the <a for=ContainerQueryList>query container</a>, and false otherwise. | ||
|
|
||
|
|
||
| When asked to <dfn export>evaluate container queries and report changes</dfn> | ||
| for a {{query container}} of the element <var>ele</var>, run these steps: | ||
| <ol> | ||
|
|
||
| <li> | ||
|
|
||
| For each {{ContainerQueryList}} object <var>target</var> that has <var>ele</var>, in the order they were created, oldest first, run these substeps: | ||
|
|
||
| <ol> | ||
|
|
||
| <li>If <var>target</var>'s <a>matches state</a> has changed since the last time these steps were run, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about describe or mention what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <a>fire an event</a> named <a event>change</a> at <var>target</var> | ||
| using {{ContainerQueryListEvent}}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we missed definition FYR: https://drafts.csswg.org/cssom-view/#mediaquerylistevent and also We may need to |
||
| with its {{Event/isTrusted}} attribute initialized to true, | ||
| its {{ContainerQueryList/container}} attribute initialized to <var>target</var>'s <a>container</a>, | ||
| and its {{ContainerQueryListEvent/matches}} attribute initialized to <var>target</var>'s <a>matches state</a>. <!--fingerprint--> | ||
|
|
||
| </ol> | ||
|
|
||
| </ol> | ||
|
|
||
| <div class='example'> | ||
| A simple piece of code that detects changes in the overflow in any of a series of elements can be written as follows: | ||
|
|
||
| <pre highlight=javascript> | ||
| function handleOverflowChange(event) { | ||
| if(event.matches) // the thing overflowed | ||
| … | ||
| else | ||
| … | ||
| } | ||
|
|
||
| const element = document.getElementById("target"); | ||
| var cql = element.matchContainer("(scroll-state(scrollable))"); | ||
| cql.onchange = handleOverflowChange; | ||
| </pre> | ||
| </div> | ||
|
|
||
| <pre class=idl> | ||
| [Exposed=Window] | ||
| interface ContainerQueryList : EventTarget { | ||
| readonly attribute CSSOMString container; | ||
| readonly attribute boolean matches; | ||
| attribute EventHandler onchange; | ||
| }; | ||
| </pre> | ||
|
|
||
| The <dfn attribute for=ContainerQueryList>container</dfn> attribute must return | ||
| the associated <a>container</a>. | ||
|
|
||
| The <dfn attribute for=ContainerQueryList>matches</dfn> attribute must return | ||
| the associated <a>matches state</a>. <!--fingerprint--> | ||
|
|
||
| The following are the <a>event handlers</a> (and their corresponding | ||
| <a>event handler event types</a>) that must be supported, as | ||
| <a>event handler IDL attributes</a>, by all objects implementing the | ||
| {{ContainerQueryList}} interface: | ||
|
|
||
| <table class="complex data"> | ||
| <thead> | ||
| <tr> | ||
| <th><a>Event handler</a> | ||
| <th><a>Event handler event type</a> | ||
| <tbody> | ||
| <tr> | ||
| <td><dfn attribute for=ContainerQueryList>onchange</dfn> | ||
| <td><a event>change</a> | ||
| </table> | ||
|
|
||
| <h3 id="the-csssupportscondition-interface"> | ||
| The <code>CSSSupportsConditionRule</code> interface</h3> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we missed the serialization rule here.
We may need to create/adopt the existing rule? https://drafts.csswg.org/cssom-1/#serialize-a-media-query-list