Skip to content

Commit 8d4c0e9

Browse files
authored
Editorial: rearrange ElementInternals into sections
As it's grown over time, some more structure seems nice. This also updates the section to the latest Web IDL conventions, e.g. "this", "method steps", etc.
1 parent 564dfd5 commit 8d4c0e9

File tree

1 file changed

+121
-101
lines changed

1 file changed

+121
-101
lines changed

source

Lines changed: 121 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -67280,7 +67280,13 @@ customElements.define("x-foo", class extends HTMLElement {
6728067280

6728167281
</div>
6728267282

67283-
<h4>The <code>ElementInternals</code> interface</h4>
67283+
<h4>Element internals</h4>
67284+
67285+
<p>Certain capabilities are meant to be available to a custom element author, but not to a custom
67286+
element consumer. These are provided by the <code
67287+
data-x="dom-attachInternals">element.attachInternals()</code> method, which returns an instance of
67288+
<code>ElementInternals</code>. The properties and methods of <code>ElementInternals</code> allow
67289+
control over internal features which the user agent provides to all elements.</p>
6728467290

6728567291
<dl class="domintro">
6728667292
<dt><var>element</var> . <code subdfn data-x="dom-attachInternals">attachInternals()</code></dt>
@@ -67291,29 +67297,74 @@ customElements.define("x-foo", class extends HTMLElement {
6729167297
element definition, or if it is called twice on the same element.</p></dd>
6729267298
</dl>
6729367299

67300+
<div w-nodev>
67301+
67302+
<p>Each <code>HTMLElement</code> has an <dfn>attached internals</dfn> boolean, initially
67303+
false.</p>
67304+
67305+
<p>The <dfn><code data-x="dom-attachInternals">attachInternals()</code></dfn> method steps
67306+
are:</p>
67307+
67308+
<ol>
67309+
<!-- We could lift this restriction in the future. -->
67310+
<li><p>If <span>this</span>'s <span data-x="concept-element-is-value"><code data-x="">is</code>
67311+
value</span> is not null, then throw a <span>"<code>NotSupportedError</code>"</span>
67312+
<code>DOMException</code>.</p></li>
67313+
67314+
<li><p>Let <var>definition</var> be the result of <span data-x="look up a custom element
67315+
definition">looking up a custom element definition</span> given this's <span>node
67316+
document</span>, its namespace, its local name, and null as the <span
67317+
data-x="concept-element-is-value"><code data-x="">is</code> value</span>.</p></li>
67318+
67319+
<li><p>If <var>definition</var> is null, then throw an
67320+
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67321+
67322+
<li><p>If <var>definition</var>'s <span
67323+
data-x="concept-custom-element-definition-disable-internals">disable internals</span> is true,
67324+
then throw a <span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67325+
67326+
<li><p>If <span>this</span>'s <span>attached internals</span> is true, then throw an
67327+
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67328+
67329+
<li><p>If <span>this</span>'s <span>custom element state</span> is not "<code
67330+
data-x="">precustomized</code>" or "<code data-x="">custom</code>", then throw a
67331+
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67332+
67333+
<li><p>Set <span>this</span>'s <span>attached internals</span> to true.</p></li>
67334+
67335+
<li><p>Return a new <code>ElementInternals</code> instance whose <span
67336+
data-x="internals-target">target element</span> is <span>this</span>.</p></li>
67337+
</ol>
67338+
67339+
<h5>The <code>ElementInternals</code> interface</h5>
67340+
67341+
<p>The IDL for the <code>ElementInternals</code> interface is as follows, with the various operations and attributes
67342+
defined in the following sections:</p>
67343+
6729467344
<pre><code class="idl">[Exposed=Window]
6729567345
interface <dfn>ElementInternals</dfn> {
67296-
// Form-associated custom elements
67346+
// <a href="#shadow-root-access">Shadow root access</a>
67347+
readonly attribute <code>ShadowRoot</code>? <span data-x="dom-ElementInternals-shadowRoot">shadowRoot</span>;
6729767348

67349+
// <a href="#form-associated-custom-elements">Form-associated custom elements</a>
6729867350
undefined <span data-x="dom-ElementInternals-setFormValue">setFormValue</span>((<span>File</span> or <span data-x="idl-USVString">USVString</span> or <span>FormData</span>)? value,
67299-
optional (<span>File</span> or <span data-x="idl-USVString">USVString</span> or <span>FormData</span>)? state);
67351+
optional (<span>File</span> or <span data-x="idl-USVString">USVString</span> or <span>FormData</span>)? state);
6730067352

6730167353
readonly attribute <span>HTMLFormElement</span>? <span data-x="dom-ElementInternals-form">form</span>;
6730267354

6730367355
undefined <span data-x="dom-ElementInternals-setValidity">setValidity</span>(optional <span>ValidityStateFlags</span> flags = {},
67304-
optional DOMString message,
67305-
optional <span>HTMLElement</span> anchor);
67356+
optional DOMString message,
67357+
optional <span>HTMLElement</span> anchor);
6730667358
readonly attribute boolean <span data-x="dom-ElementInternals-willValidate">willValidate</span>;
6730767359
readonly attribute <span>ValidityState</span> <span data-x="dom-ElementInternals-validity">validity</span>;
6730867360
readonly attribute DOMString <span data-x="dom-ElementInternals-validationMessage">validationMessage</span>;
6730967361
boolean <span data-x="dom-ElementInternals-checkValidity">checkValidity</span>();
6731067362
boolean <span data-x="dom-ElementInternals-reportValidity">reportValidity</span>();
6731167363

6731267364
readonly attribute <span>NodeList</span> <span data-x="dom-ElementInternals-labels">labels</span>;
67313-
67314-
readonly attribute <code>ShadowRoot</code>? <span data-x="dom-ElementInternals-shadowRoot">shadowRoot</span>;
6731567365
};
6731667366

67367+
// <a href="#accessibility-semantics">Accessibility semantics</a>
6731767368
ElementInternals includes <span>ARIAMixin</span>;
6731867369

6731967370
dictionary <dfn>ValidityStateFlags</dfn> {
@@ -67329,6 +67380,43 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6732967380
boolean customError = false;
6733067381
};</code></pre>
6733167382

67383+
<p>Each <code>ElementInternals</code> has a <dfn data-x="internals-target">target element</dfn>,
67384+
which is a <span>custom element</span>.</p>
67385+
67386+
</div>
67387+
67388+
<h5>Shadow root access</h5>
67389+
67390+
<dl class="domintro">
67391+
<dt><var>internals</var> . <code data-x="dom-ElementInternals-shadowRoot">shadowRoot</code></dt>
67392+
<dd><p>Returns the <code>ShadowRoot</code> for <var>internals</var>'s
67393+
<span data-x="internals-target">target element</span>, if the
67394+
<span data-x="internals-target">target element</span> is a <span>shadow host</span>, or null
67395+
otherwise.</p></dd>
67396+
</dl>
67397+
67398+
<div w-nodev>
67399+
<p>The <dfn><code data-x="dom-ElementInternals-shadowRoot">shadowRoot</code></dfn> getter steps
67400+
are:</p>
67401+
67402+
<ol>
67403+
<li><p>Let <var>target</var> be <span>this</span>'s <span data-x="internals-target">target
67404+
element</span>.</p></li>
67405+
67406+
<li><p>If <var>target</var> is not a <span>shadow host</span>, then return null.</p></li>
67407+
67408+
<li><p>Let <var>shadow</var> be <var>target</var>'s <span
67409+
data-x="concept-element-shadow-root">shadow root</span>.</p></li>
67410+
67411+
<li><p>If <var>shadow</var>'s <span>available to element internals</span> is false, then return
67412+
null.</p></li>
67413+
67414+
<li><p>Return <var>shadow</var>.</p></li>
67415+
</ol>
67416+
</div>
67417+
67418+
<h5>Form-associated custom elements</h5>
67419+
6733267420
<dl class="domintro">
6733367421
<dt><var>internals</var> . <code data-x="dom-ElementInternals-setFormValue">setFormValue</code>(<var>value</var>)</dt>
6733467422
<dd>
@@ -67400,89 +67488,11 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6740067488
<dd><p>Returns a <code>NodeList</code> of all the <code>label</code> elements that
6740167489
<var>internals</var>'s <span data-x="internals-target">target element</span> is associated
6740267490
with.</p></dd>
67403-
67404-
<dt><var>internals</var> . <code data-x=""><a href="#dom-ElementInternals-accessibility-idl-get">role</a></code> [ = <var>value</var> ]</dt>
67405-
<dd><p>Sets or retrieves the default ARIA role for <var>internals</var>'s <span
67406-
data-x="internals-target">target element</span>, which will be used unless the page author
67407-
overrides it using the <code data-x="attr-aria-role">role</code> attribute.</p></dd>
67408-
67409-
<dt><var>internals</var> . <code data-x=""><a href="#dom-ElementInternals-accessibility-idl-get">aria*</a></code> [ = <var>value</var> ]</dt>
67410-
<dd><p>Sets or retrieves various default ARIA states or property values for
67411-
<var>internals</var>'s <span data-x="internals-target">target element</span>, which will be used
67412-
unless the page author overrides them using the <code data-x="attr-aria-*">aria-*</code>
67413-
attributes.</p></dd>
67414-
67415-
<dt><var>internals</var> . <code data-x="dom-ElementInternals-shadowRoot">shadowRoot</code></dt>
67416-
<dd><p>Returns the <code>ShadowRoot</code> for <var>internals</var>'s
67417-
<span data-x="internals-target">target element</span>, if the
67418-
<span data-x="internals-target">target element</span> is a <span>shadow host</span>, or null
67419-
otherwise.</p></dd>
6742067491
</dl>
6742167492

67422-
<p>Each <code>ElementInternals</code> has a <dfn data-x="internals-target">target element</dfn>,
67423-
which is a <span>custom element</span>. <code>ElementInternals</code> provides various operations
67424-
and attributes to allow control over internal features which the user agent provides to all
67425-
elements.</p>
67426-
67427-
<p>Each <code>HTMLElement</code> has an <dfn>attached internals</dfn> boolean, initially
67428-
false.</p>
67429-
67430-
<p>The <dfn><code data-x="dom-attachInternals">attachInternals()</code></dfn> method on
67431-
an <code>HTMLElement</code> <var>element</var>, when invoked, must run the following steps:</p>
67432-
67433-
<ol>
67434-
<!-- We could lift this restriction in the future. -->
67435-
<li><p>If <var>element</var>'s <span data-x="concept-element-is-value"><code
67436-
data-x="">is</code> value</span> is not null, then throw a
67437-
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67438-
67439-
<li><p>Let <var>definition</var> be the result of <span
67440-
data-x="look up a custom element definition">looking up a custom element definition</span> given
67441-
<var>element</var>'s <span>node document</span>, its namespace, its local name, and null as
67442-
<span data-x="concept-element-is-value"><code data-x="">is</code> value</span>.</p></li>
67443-
67444-
<li><p>If <var>definition</var> is null, then throw an
67445-
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67446-
67447-
<li><p>If <var>definition</var>'s <span
67448-
data-x="concept-custom-element-definition-disable-internals">disable internals</span> is true,
67449-
then throw a <span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67450-
67451-
<li><p>If <var>element</var>'s <span>attached internals</span> is true, then throw an
67452-
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67453-
67454-
<li><p>If <var>element</var>'s <span>custom element state</span> is not "<code
67455-
data-x="">precustomized</code>" or "<code data-x="">custom</code>", then throw a
67456-
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
67457-
67458-
<li><p>Set <var>element</var>'s <span>attached internals</span> to true.</p></li>
67459-
67460-
<li><p>Create a new <code>ElementInternals</code> instance
67461-
<span data-x="internals-target">targeting</span> <var>element</var>, and return it.</p></li>
67462-
</ol>
67463-
67464-
<p>The <dfn><code data-x="dom-ElementInternals-shadowRoot">shadowRoot</code></dfn> getter steps are:
67465-
67466-
<ol>
67467-
<li><p>Let <var>target</var> be <code>ElementInternals</code>'s <span
67468-
data-x="internals-target">target element</span>.</p></li>
67469-
67470-
<li><p>If <var>target</var> is not a <span>shadow host</span>, then return null.</p></li>
67471-
67472-
<li><p>Let <var>shadow</var> be <var>target</var>'s
67473-
<span data-x="concept-element-shadow-root">shadow root</span>.</p></li>
67474-
67475-
<li><p>If <var>shadow</var>'s <span>available to element internals</span> is false, then return
67476-
null.</p></li>
67477-
67478-
<li><p>Return <var>shadow</var>.</p></li>
67479-
</ol>
67480-
67481-
<hr>
67482-
6748367493
<p>Each <span>form-associated custom element</span> has <dfn
6748467494
data-x="face-submission-value">submission value</dfn>. It is used to provide one or more
67485-
<span data-x="formdata-entry">entries</span> on form submission, and
67495+
<span data-x="formdata-entry">entries</span> on form submission.
6748667496
The initial value of <span data-x="face-submission-value">submission value</span> is null, and
6748767497
<span data-x="face-submission-value">submission value</span> can be null, a string, a
6748867498
<code>File</code>, or a <span>list</span> of <span data-x="formdata-entry">entries</span>.</p>
@@ -67533,12 +67543,11 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6753367543
<div w-nodev>
6753467544

6753567545
<p>The <dfn><code data-x="dom-ElementInternals-setFormValue">setFormValue(<var>value</var>,
67536-
<var>state</var>)</code></dfn> method of the <code>ElementInternals</code> interface must
67537-
run the following steps:</p>
67546+
<var>state</var>)</code></dfn> method steps are:</p>
6753867547

6753967548
<ol>
67540-
<li><p>Let <var>element</var> be this <code>ElementInternals</code>'s <span
67541-
data-x="internals-target">target element</span>.</p></li>
67549+
<li><p>Let <var>element</var> be <span>this</span>'s <span data-x="internals-target">target
67550+
element</span>.</p></li>
6754267551

6754367552
<li><p>If <var>element</var> is not a <span>form-associated custom element</span>, then throw a
6754467553
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
@@ -67577,12 +67586,11 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6757767586
<dfn data-x="face-validation-anchor">validation anchor</dfn> element. It is null initially.</p>
6757867587

6757967588
<p>The <dfn><code data-x="dom-ElementInternals-setValidity">setValidity(<var>flags</var>,
67580-
<var>message</var>, <var>anchor</var>)</code></dfn> method of the <code>ElementInternals</code>
67581-
interface must run the following steps:</p>
67589+
<var>message</var>, <var>anchor</var>)</code></dfn> method steps are:</p>
6758267590

6758367591
<ol>
67584-
<li><p>Let <var>element</var> be this <code>ElementInternals</code>'s <span
67585-
data-x="internals-target">target element</span>.</p></li>
67592+
<li><p>Let <var>element</var> be <span>this</span>'s <span data-x="internals-target">target
67593+
element</span>.</p></li>
6758667594

6758767595
<li><p>If <var>element</var> is not a <span>form-associated custom element</span>, then throw a
6758867596
<span>"<code>NotSupportedError</code>"</span> <code>DOMException</code>.</p></li>
@@ -67611,13 +67619,12 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6761167619
</ol>
6761267620

6761367621
<p>The <dfn><code data-x="dom-ElementInternals-validationMessage">validationMessage</code></dfn>
67614-
attribute of <code>ElementInternals</code> interface, on getting, must return the
67615-
<span data-x="face-validation-message">validation message</span> of this
67616-
<code>ElementInternals</code>'s <span data-x="internals-target">target element</span>.</p>
67622+
getter steps are to return the <span data-x="face-validation-message">validation message</span> of
67623+
<span>this</span>'s <span data-x="internals-target">target element</span>.</p>
6761767624

67618-
<p>When <dfn data-x="face-entry-construction">entry construction algorithm</dfn> for a
67619-
<span>form-associated custom element</span> is invoked, given an element <var>element</var> and a
67620-
list <var>entry list</var>, run the following steps:</p>
67625+
<p>The <dfn data-x="face-entry-construction">entry construction algorithm</dfn> for a
67626+
<span>form-associated custom element</span>, given an element <var>element</var> and a
67627+
list <var>entry list</var>, consists of the following steps:</p>
6762167628

6762267629
<ol>
6762367630
<li>
@@ -67647,7 +67654,20 @@ dictionary <dfn>ValidityStateFlags</dfn> {
6764767654

6764867655
</div>
6764967656

67650-
<hr>
67657+
<h5>Accessibility semantics</h5>
67658+
67659+
<dl class="domintro">
67660+
<dt><var>internals</var> . <code data-x=""><a href="#dom-ElementInternals-accessibility-idl-get">role</a></code> [ = <var>value</var> ]</dt>
67661+
<dd><p>Sets or retrieves the default ARIA role for <var>internals</var>'s <span
67662+
data-x="internals-target">target element</span>, which will be used unless the page author
67663+
overrides it using the <code data-x="attr-aria-role">role</code> attribute.</p></dd>
67664+
67665+
<dt><var>internals</var> . <code data-x=""><a href="#dom-ElementInternals-accessibility-idl-get">aria*</a></code> [ = <var>value</var> ]</dt>
67666+
<dd><p>Sets or retrieves various default ARIA states or property values for
67667+
<var>internals</var>'s <span data-x="internals-target">target element</span>, which will be used
67668+
unless the page author overrides them using the <code data-x="attr-aria-*">aria-*</code>
67669+
attributes.</p></dd>
67670+
</dl>
6765167671

6765267672
<p w-nohtml>By using the <code data-x="">role</code> and <code data-x="">aria*</code> properties
6765367673
of <code>ElementInternals</code>, custom element authors can set default accessibile roles,

0 commit comments

Comments
 (0)