Skip to content

Commit

Permalink
Update textarea textContent/defaultValue/value interaction
Browse files Browse the repository at this point in the history
This fixes #2752, where it was revealed that most browsers do not care
about the textContent of a textarea, but instead about its child text
content. That is, if you use the DOM APIs to insert a child element into
the textarea element, its text does not show up for editing or as part
of the value and defaultValue properties (even though it shows up in
textContent).

This moves to a model where textareas operate entirely on the child text
content. This matches Blink and Gecko, and somewhat matches WebKit.

This also fixes #2750, by using the newly-introduced "child text content
change steps" hook introduced to DOM in
whatwg/dom#466.
  • Loading branch information
domenic committed Jun 27, 2017
1 parent ee19894 commit 5afbba1
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -1971,10 +1971,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
or string, means that the length of the text is zero (i.e., not even containing <span
data-x="control">controls</span> or U+0020 SPACE).</p>

<p>An element's <dfn data-export="">child text content</dfn> is the concatenation of the <span
data-x="concept-cd-data">data</span> of all the <code>Text</code> nodes that are children of the
element (ignoring any other nodes such as comments or elements), in <span>tree order</span>.</p>

<p>A <dfn data-x="nodes are inserted">node <var>A</var> is inserted</dfn> into a node <var>B</var>
when the <span data-x="concept-node-insert-ext">insertion steps</span> are invoked with
<var>A</var> as the argument and <var>A</var>'s new parent is <var>B</var>. Similarly, a <dfn
Expand Down Expand Up @@ -3029,10 +3025,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-pre-insert">pre-insert</dfn>, <dfn data-x="concept-node-insert" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert">insert</dfn>, <dfn data-x="concept-node-append" data-x-href="https://dom.spec.whatwg.org/#concept-node-append">append</dfn>, <dfn data-x="concept-node-replace" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace">replace</dfn>, <dfn data-x="concept-node-replace-all" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace-all">replace all</dfn>, <dfn data-x="concept-node-remove" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove">remove</dfn>, and <dfn data-x="concept-node-adopt" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt">adopt</dfn> algorithms for nodes</li>
<li>The <dfn data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, <dfn data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn>, and <dfn data-x="concept-element-attributes-set-value" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-set-value">set value</dfn> algorithms for attributes</li>
<li>The <dfn data-x="concept-node-insert-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert-ext">insertion steps</dfn>,
<dfn data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>, and
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn> hooks</li>
<dfn data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>,
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn>, and
<dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">child text content change steps</dfn> hooks</li>
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-element-attribute">attribute list</dfn> concept</li>
<li>The <dfn data-x="concept-cd-data" data-x-href="https://dom.spec.whatwg.org/#concept-cd-data">data</dfn> of a text node</li>
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-child-text-content">child text content</dfn> of a node</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-event"><code>Event</code></dfn> interface</li>
<li><dfn data-x-href="https://dom.spec.whatwg.org/#interface-eventtarget"><code>EventTarget</code></dfn> interface</li>
<li>The <!--en-GB--><dfn id="activation-behaviour" data-x-href="https://dom.spec.whatwg.org/#eventtarget-activation-behavior">activation behavior</dfn> hook</li>
Expand Down Expand Up @@ -50481,15 +50479,15 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
elements must propagate the <span data-x="concept-textarea-raw-value">raw value</span> and <span
data-x="concept-fe-dirty">dirty value flag</span> from the node being cloned to the copy.</p>

<p>When the <code>textarea</code> element's <code>textContent</code> IDL attribute changes value,
if the element's <span data-x="concept-fe-dirty">dirty value flag</span> is false, then the
element's <span data-x="concept-textarea-raw-value">raw value</span> must be set to the value of
the element's <code>textContent</code> IDL attribute.</p>
<p>The <span>child text content change steps</span> for <code>textarea</code> elements must, if
the element's <span data-x="concept-fe-dirty">dirty value flag</span> is false, set the element's
<span data-x="concept-textarea-raw-value">raw value</span> to its <span>child text
content</span>.</p>

<p>The <span data-x="concept-form-reset-control">reset algorithm</span> for <code>textarea</code>
elements is to set the <span data-x="concept-fe-dirty">dirty value flag</span> back to false, and
set the <span data-x="concept-textarea-raw-value">raw value</span> of element to the value of the
element's <code>textContent</code> IDL attribute.</p>
set the <span data-x="concept-textarea-raw-value">raw value</span> of element to its <span>child
text content</span>.</p>

<p>When a <code>textarea</code> element is popped off the <span>stack of open elements</span> of
an <span>HTML parser</span> or <span>XML parser</span>, then the user agent must invoke the
Expand Down Expand Up @@ -50750,8 +50748,9 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
<p>The <dfn><code data-x="dom-textarea-type">type</code></dfn> IDL attribute must return the value
"<code data-x="">textarea</code>".</p>

<p>The <dfn><code data-x="dom-textarea-defaultValue">defaultValue</code></dfn> IDL attribute must
act like the element's <code>textContent</code> IDL attribute.</p>
<p>The <dfn><code data-x="dom-textarea-defaultValue">defaultValue</code></dfn> IDL attribute must,
on getting, return the element's <span>child text content</span>. On setting, it must act as the
setter for the element's <code>textContent</code> IDL attribute.</p>

<p>The <dfn><code data-x="dom-textarea-value">value</code></dfn> IDL attribute must, on getting,
return the element's <span data-x="concept-fe-api-value">API value</span>. On setting, it must
Expand Down

1 comment on commit 5afbba1

@triple-underscore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link URL for the term “child text content change steps” seems wrong:
https://dom.spec.whatwg.org/#concept-node-adopt-ext

which should probably be:
https://dom.spec.whatwg.org/#concept-node-text-change-ext

Please sign in to comment.