Skip to content

Commit b417e88

Browse files
authored
Fire "input" events as composed
This is how things have been implemented in all browsers, probably based off of the definitions in the UI Events specification. See also the discussion in #5453. This includes an editorial change to deduplicate some repeated text in the <input type=file> section.
1 parent 15401c3 commit b417e88

File tree

1 file changed

+57
-46
lines changed

1 file changed

+57
-46
lines changed

source

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
29722972
<li><dfn data-x="dom-Event-currentTarget" data-x-href="https://dom.spec.whatwg.org/#dom-event-currenttarget"><code>currentTarget</code></dfn> attribute</li>
29732973
<li><dfn data-x="dom-Event-bubbles" data-x-href="https://dom.spec.whatwg.org/#dom-event-bubbles"><code>bubbles</code></dfn> attribute</li>
29742974
<li><dfn data-x="dom-Event-cancelable" data-x-href="https://dom.spec.whatwg.org/#dom-event-cancelable"><code>cancelable</code></dfn> attribute</li>
2975+
<li><dfn data-x="dom-Event-composed" data-x-href="https://dom.spec.whatwg.org/#dom-event-composed"><code>composed</code></dfn> attribute</li>
29752976
<li><dfn data-x-href="https://dom.spec.whatwg.org/#composed-flag">composed flag</dfn></li>
29762977
<li><dfn data-x="dom-Event-isTrusted" data-x-href="https://dom.spec.whatwg.org/#dom-event-istrusted"><code>isTrusted</code></dfn> attribute</li>
29772978
<li><dfn data-x="dom-Event-initEvent" data-x-href="https://dom.spec.whatwg.org/#dom-event-initevent"><code>initEvent()</code></dfn> method</li>
@@ -45048,7 +45049,8 @@ interface <dfn>HTMLInputElement</dfn> : <span>HTMLElement</span> {
4504845049
<li><p><span>Queue an element task</span> on the <span>user interaction task source</span> given
4504945050
the element to <span data-x="concept-event-fire">fire an event</span> named <code
4505045051
data-x="event-input">input</code> at the element, with the <code
45051-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
45052+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
45053+
attributes initialized to true.</p></li>
4505245054
</ol>
4505345055

4505445056
</div>
@@ -47033,7 +47035,8 @@ ldh-str = &lt; as defined in <a href="https://tools.ietf.org/html/rfc1034#
4703347035

4703447036
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4703547037
data-x="event-input">input</code> at the element with the <code
47036-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
47038+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
47039+
attributes initialized to true.</p></li>
4703747040

4703847041
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4703947042
data-x="event-change">change</code> at the element with the <code
@@ -47189,7 +47192,8 @@ ldh-str = &lt; as defined in <a href="https://tools.ietf.org/html/rfc1034#
4718947192

4719047193
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4719147194
data-x="event-input">input</code> at the element with the <code
47192-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
47195+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
47196+
attributes initialized to true.</p></li>
4719347197

4719447198
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4719547199
data-x="event-change">change</code> at the element with the <code
@@ -47343,41 +47347,42 @@ ldh-str = &lt; as defined in <a href="https://tools.ietf.org/html/rfc1034#
4734347347

4734447348
<li><p>Wait for the user to have made their selection.</p></li>
4734547349

47346-
<li>
47347-
<p><span>Queue an element task</span> on the <span>user interaction task source</span> given
47348-
the <code>input</code> element and the following steps:</p>
47349-
47350-
<ol>
47351-
<li><p>Update the element's <span data-x="concept-input-type-file-selected">selected
47352-
files</span> so that it represents the user's selection.</p></li>
47353-
47354-
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
47355-
data-x="event-input">input</code> at the <code>input</code> element, with the <code
47356-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true, and finally <span
47357-
data-x="concept-event-fire">fire an event</span> named <code
47358-
data-x="event-change">change</code> at the <code>input</code> element, with the <code
47359-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
47360-
</ol>
47361-
</li>
47350+
<li><p><span>Update the file selection</span> for the <code>input</code> element.</p></li>
4736247351
</ol>
4736347352
</li>
4736447353
</ol>
4736547354

4736647355
<p>If the element is <i data-x="concept-fe-mutable">mutable</i>, the user agent should allow the
47367-
user to change the files on the list in other ways also, e.g. adding or removing files by
47368-
drag-and-drop. When the user does so, the user agent must <span>queue an element task</span> on
47369-
the <span>user interaction task source</span> given the <code>input</code> element to first update
47370-
the element's <span data-x="concept-input-type-file-selected">selected files</span> so that it
47371-
represents the user's new selection, then <span data-x="concept-event-fire">fire an event</span>
47372-
named <code data-x="event-input">input</code> at the <code>input</code> element, with the <code
47373-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true, and finally <span
47374-
data-x="concept-event-fire">fire an event</span> named <code data-x="event-change">change</code>
47375-
at the <code>input</code> element, with the <code data-x="dom-Event-bubbles">bubbles</code>
47376-
attribute initialized to true.</p>
47356+
user to change the files on the list in other ways also, e.g., adding or removing files by
47357+
drag-and-drop. When the user does so, the user agent must <span>update the file selection</span>
47358+
for the element.</p>
4737747359

4737847360
<p>If the element is not <i data-x="concept-fe-mutable">mutable</i>, the user agent must not allow
4737947361
the user to change the element's selection.</p>
4738047362

47363+
<p>To <dfn>update the file selection</dfn> for an element <var>element</var>:</p>
47364+
47365+
<ol>
47366+
<li>
47367+
<p><span>Queue an element task</span> on the <span>user interaction task source</span> given
47368+
<var>element</var> and the following steps:</p>
47369+
47370+
<ol>
47371+
<li><p>Update <var>element</var>'s <span data-x="concept-input-type-file-selected">selected
47372+
files</span> so that it represents the user's selection.</p></li>
47373+
47374+
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
47375+
data-x="event-input">input</code> at the <code>input</code> element, with the <code
47376+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
47377+
attributes initialized to true.</p></li>
47378+
47379+
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
47380+
data-x="event-change">change</code> at the <code>input</code> element, with the <code
47381+
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
47382+
</ol>
47383+
</li>
47384+
</ol>
47385+
4738147386
<p><strong>Constraint validation</strong>: If the element is <i
4738247387
data-x="concept-input-required">required</i> and the list of <span
4738347388
data-x="concept-input-type-file-selected">selected files</span> is empty, then the element is
@@ -49359,12 +49364,12 @@ You cannot submit this form when the field is incorrect.</samp></pre>
4935949364
<span>queue an element task</span> on the <span>user interaction task source</span> given the
4936049365
<code>input</code> element to <span data-x="concept-event-fire">fire an event</span> named <code
4936149366
data-x="event-input">input</code> at the <code>input</code> element, with the <code
49362-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true, and any time the user
49363-
commits the change, the user agent must <span>queue an element task</span> on the <span>user
49364-
interaction task source</span> given the <code>input</code> element to <span
49365-
data-x="concept-event-fire">fire an event</span> named <code data-x="event-change">change</code>
49366-
at the <code>input</code> element, with the <code data-x="dom-Event-bubbles">bubbles</code>
49367-
attribute initialized to true.</p>
49367+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
49368+
attributes initialized to true, and any time the user commits the change, the user agent must
49369+
<span>queue an element task</span> on the <span>user interaction task source</span> given the
49370+
<code>input</code> element to <span data-x="concept-event-fire">fire an event</span> named <code
49371+
data-x="event-change">change</code> at the <code>input</code> element, with the <code
49372+
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p>
4936849373

4936949374
<p class="example">An example of a user interface involving both interactive manipulation and a
4937049375
commit action would be a <span data-x="attr-input-type-range">Range</span> controls that use a
@@ -49380,7 +49385,8 @@ You cannot submit this form when the field is incorrect.</samp></pre>
4938049385
agent must <span>queue an element task</span> on the <span>user interaction task source</span>
4938149386
given the <code>input</code> element to first <span data-x="concept-event-fire">fire an
4938249387
event</span> named <code data-x="event-input">input</code> at the <code>input</code> element, with
49383-
the <code data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true, and then <span
49388+
the <code data-x="dom-Event-bubbles">bubbles</code> and <code
49389+
data-x="dom-Event-composed">composed</code> attributes initialized to true, and then <span
4938449390
data-x="concept-event-fire">fire an event</span> named <code data-x="event-change">change</code>
4938549391
at the <code>input</code> element, with the <code data-x="dom-Event-bubbles">bubbles</code>
4938649392
attribute initialized to true.</p>
@@ -49403,9 +49409,10 @@ You cannot submit this form when the field is incorrect.</samp></pre>
4940349409
action, the user agent must <span>queue an element task</span> on the <span>user interaction task
4940449410
source</span> given the <code>input</code> element to <span data-x="concept-event-fire">fire an
4940549411
event</span> named <code data-x="event-input">input</code> at the <code>input</code> element, with
49406-
the <code data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true. The
49407-
corresponding <code data-x="event-change">change</code> event, if any, will be fired when the
49408-
control <a href="#unfocus-causes-change-event">loses focus</a>.</p>
49412+
the <code data-x="dom-Event-bubbles">bubbles</code> and <code
49413+
data-x="dom-Event-composed">composed</code> attributes initialized to true. The corresponding
49414+
<code data-x="event-change">change</code> event, if any, will be fired when the control <a
49415+
href="#unfocus-causes-change-event">loses focus</a>.</p>
4940949416

4941049417
<p class="example">Examples of a user changing the element's <span
4941149418
data-x="concept-fe-value">value</span> would include the user typing into a text control, pasting
@@ -49432,7 +49439,8 @@ You cannot submit this form when the field is incorrect.</samp></pre>
4943249439
task source</span> given the <code>input</code> element to first update the <span
4943349440
data-x="concept-fe-value">value</span> accordingly, then <span data-x="concept-event-fire">fire an
4943449441
event</span> named <code data-x="event-input">input</code> at the <code>input</code> element, with
49435-
the <code data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true, then <span
49442+
the <code data-x="dom-Event-bubbles">bubbles</code> and <code
49443+
data-x="dom-Event-composed">composed</code> attributes initialized to true, then <span
4943649444
data-x="concept-event-fire">fire an event</span> named <code data-x="event-change">change</code>
4943749445
at the <code>input</code> element, with the <code data-x="dom-Event-bubbles">bubbles</code>
4943849446
attribute initialized to true.</p>
@@ -49882,7 +49890,8 @@ interface <dfn>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
4988249890
<ol>
4988349891
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4988449892
data-x="event-input">input</code> at the <code>select</code> element, with the <code
49885-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
49893+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
49894+
attributes initialized to true.</p></li>
4988649895

4988749896
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
4988849897
data-x="event-change">change</code> at the <code>select</code> element, with the <code
@@ -50780,10 +50789,11 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
5078050789
element task</span> on the <span>user interaction task source</span> given the
5078150790
<code>textarea</code> element to <span data-x="concept-event-fire">fire an event</span> named
5078250791
<code data-x="event-input">input</code> at the <code>textarea</code> element, with the <code
50783-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true. User agents may wait for
50784-
a suitable break in the user's interaction before queuing the task; for example, a user agent
50785-
could wait for the user to have not hit a key for 100ms, so as to only fire the event when the
50786-
user pauses, instead of continuously for each keystroke.</p>
50792+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
50793+
attributes initialized to true. User agents may wait for a suitable break in the user's
50794+
interaction before queuing the task; for example, a user agent could wait for the user to have not
50795+
hit a key for 100ms, so as to only fire the event when the user pauses, instead of continuously
50796+
for each keystroke.</p>
5078750797
<!-- same text is present in the <input> section -->
5078850798

5078950799
<p>A <code>textarea</code> element's <span data-x="concept-fe-dirty">dirty value flag</span> must
@@ -50824,7 +50834,8 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
5082450834
<li><p><span>Queue an element task</span> on the <span>user interaction task source</span> given
5082550835
the <code>textarea</code> element to <span data-x="concept-event-fire">fire an event</span> named
5082650836
<code data-x="event-input">input</code> at the <code>textarea</code> element, with the <code
50827-
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
50837+
data-x="dom-Event-bubbles">bubbles</code> and <code data-x="dom-Event-composed">composed</code>
50838+
attributes initialized to true.</p></li>
5082850839
</ol>
5082950840

5083050841
</div>

0 commit comments

Comments
 (0)