Skip to content

Commit

Permalink
Correct a few links and formatting things
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino committed Dec 17, 2024
1 parent 6423bfa commit ded78da
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x="dom-Node-append" data-x-href="https://dom.spec.whatwg.org/#dom-node-append"><code>append()</code></dfn> method</li>
<li><dfn data-x="dom-Node-appendChild" data-x-href="https://dom.spec.whatwg.org/#dom-node-appendchild"><code>appendChild()</code></dfn> method</li>
<li><dfn data-x="dom-Node-cloneNode" data-x-href="https://dom.spec.whatwg.org/#dom-node-clonenode"><code>cloneNode()</code></dfn> method</li>
<li><dfn data-x="dom-Node-moveBefore" data-x-href="https://dom.spec.whatwg.org/#dom-node-moveBefore"><code>moveBefore()</code></dfn> method</li>
<li><dfn data-x="dom-ParentNode-moveBefore" data-x-href="https://dom.spec.whatwg.org/#dom-parentnode-movebefore"><code>moveBefore()</code></dfn> method</li>
<li><dfn data-x="dom-Document-importNode" data-x-href="https://dom.spec.whatwg.org/#dom-document-importnode"><code>importNode()</code></dfn> method</li>
<li><dfn data-x="dom-Event-preventDefault" data-x-href="https://dom.spec.whatwg.org/#dom-event-preventdefault"><code>preventDefault()</code></dfn> method</li>
<li><dfn data-x="dom-Element-id" data-x-href="https://dom.spec.whatwg.org/#dom-element-id"><code>id</code></dfn> attribute</li>
Expand Down Expand Up @@ -72452,60 +72452,60 @@ document.body.append(parent);
elements as well. By default, the "<code data-x="">disconnectedCallback</code>" and "<code
data-x="">connectedCallback</code>" would be called on the element, one after the other. This is
done to maintain compatibility with existing custom elements that predate the <code
data-x="dom-Node-moveBefore">moveBefore</code> method. This means that by default, custom elements
data-x="dom-ParentNode-moveBefore">moveBefore()</code> method. This means that by default, custom elements
reset their state as if they were removed and re-inserted. In the example <a
href="#custom-elements-autonomous-drawbacks-example">above</a>, the impact would be that the
observer would be disconnected and re-connected, and the tab index would be reset.</p>

<p>To opt in to a state-preserving behavior while <span
data-x="concept-node-move-ext">moveing</span>, the author can implement a "<code
data-x="concept-node-move-ext">moving</span>, the author can implement a "<code
data-x="">connectedMoveCallback</code>". The existence of this callback, even if empty, would
supercede the default behavior of calling "<code data-x="">disconnectedCallback</code>" and "<code
data-x="">connectedCallback</code>". "<code data-x="">connectedMoveCallback</code>" can also be
an appropriate place to execute logic that depends on the element's ancestors. For example:</p>

<pre><code class="js">class TacoButton extends HTMLElement {
static observedAttributes = ["disabled"];
static observedAttributes = ["disabled"];

constructor() {
super();
this._internals = this.attachInternals();
this._internals.role = "button";
constructor() {
super();
this._internals = this.attachInternals();
this._internals.role = "button";

this._observer = new MutationObserver(() => {
this._internals.ariaLabel = this.textContent;
});
}
this._observer = new MutationObserver(() => {
this._internals.ariaLabel = this.textContent;
});
}

_notifyMain() {
if (this.parentElement.tagName === "MAIN") {
// Execute logic that depends on ancestors.
}
_notifyMain() {
if (this.parentElement.tagName === "MAIN") {
// Execute logic that depends on ancestors.
}
}

connectedCallback() {
this.setAttribute("tabindex", "0");
connectedCallback() {
this.setAttribute("tabindex", "0");

this._observer.observe(this, {
childList: true,
characterData: true,
subtree: true
});
this._observer.observe(this, {
childList: true,
characterData: true,
subtree: true
});

this._notifyMain();
}
this._notifyMain();
}

disconnectedCallback() {
this._observer.disconnect();
}
disconnectedCallback() {
this._observer.disconnect();
}

// Implementing this function would avoid resetting the tab index or re-registering the
// mutation observer when this element is moved inside the DOM without being disconnected.
connectedMoveCallback() {
// The parent can change during a state-preserving move.
this._notifyMain();
}
}</code></pre>
connectedMoveCallback() {
// The parent can change during a state-preserving move.
this._notifyMain();
}
}</code></pre>

<h4 id="custom-elements-core-concepts">Core concepts</h4>

Expand Down

0 comments on commit ded78da

Please sign in to comment.