|
| 1 | +<h3 id="events-inputevents">Input Events</h3> |
| 2 | + |
| 3 | + Input events are sent as notifications whenever the DOM is being updated (or about |
| 4 | + to be updated) as a direct result of a user action (e.g., keyboard input in an editable |
| 5 | + region, deleting or formatting text, ...). |
| 6 | + |
| 7 | + <h4 id="interface-inputevent">Interface InputEvent</h4> |
| 8 | + |
| 9 | + <h5 id="idl-inputevent">InputEvent</h5> |
| 10 | + |
| 11 | + <p class="intro-dom">Introduced in DOM Level 3</p> |
| 12 | + |
| 13 | + <pre class="idl"> |
| 14 | + [Exposed=Window] |
| 15 | + interface InputEvent : UIEvent { |
| 16 | + constructor(DOMString type, optional InputEventInit eventInitDict = {}); |
| 17 | + readonly attribute USVString? data; |
| 18 | + readonly attribute boolean isComposing; |
| 19 | + readonly attribute DOMString inputType; |
| 20 | + }; |
| 21 | + </pre> |
| 22 | + |
| 23 | + <dl dfn-for="InputEvent"> |
| 24 | + <dt><dfn attribute>data</dfn></dt> |
| 25 | + <dd> |
| 26 | + <code>data</code> holds the value of the characters generated by |
| 27 | + an input method. This MAY be a single Unicode character or a |
| 28 | + non-empty sequence of Unicode characters [[Unicode]]. Characters |
| 29 | + SHOULD be normalized as defined by the Unicode normalization |
| 30 | + form <em>NFC</em>, defined in [[UAX15]]. |
| 31 | + This attribute MAY contain the <a>empty string</a>. |
| 32 | + |
| 33 | + The <a>un-initialized value</a> of this attribute MUST be |
| 34 | + <code>null</code>. |
| 35 | + </dd> |
| 36 | + |
| 37 | + <dt><dfn attribute>isComposing</dfn></dt> |
| 38 | + <dd> |
| 39 | + <code>true</code> if the input event occurs as part of a |
| 40 | + composition session, i.e., after a EVENT{compositionstart} event |
| 41 | + and before the corresponding EVENT{compositionend} event. |
| 42 | + |
| 43 | + The <a>un-initialized value</a> of this attribute MUST be |
| 44 | + <code>false</code>. |
| 45 | + </dd> |
| 46 | + |
| 47 | + <dt><dfn attribute>inputType</dfn></dt> |
| 48 | + <dd> |
| 49 | + <code>inputType</code> contains a string that identifies the type |
| 50 | + of input associated with the event. |
| 51 | + |
| 52 | + For a list of valid values for this attribute, refer to the |
| 53 | + [[Input-Events]] specification. |
| 54 | + |
| 55 | + The <a>un-initialized value</a> of this attribute MUST be |
| 56 | + the empty string <code>""</code>. |
| 57 | + </dd> |
| 58 | + </dl> |
| 59 | + |
| 60 | + <h5 id="idl-inputeventinit">InputEventInit</h5> |
| 61 | + |
| 62 | + <pre class="idl"> |
| 63 | + dictionary InputEventInit : UIEventInit { |
| 64 | + DOMString? data = null; |
| 65 | + boolean isComposing = false; |
| 66 | + DOMString inputType = ""; |
| 67 | + }; |
| 68 | + </pre> |
| 69 | + |
| 70 | + <dl dfn-for="InputEventInit"> |
| 71 | + <dt><dfn dict-member>data</dfn></dt> |
| 72 | + <dd> |
| 73 | + Initializes the <code>data</code> attribute of the InputEvent object. |
| 74 | + </dd> |
| 75 | + |
| 76 | + <dt><dfn dict-member>isComposing</dfn></dt> |
| 77 | + <dd> |
| 78 | + Initializes the <code>isComposing</code> attribute of the InputEvent object. |
| 79 | + </dd> |
| 80 | + |
| 81 | + <dt><dfn dict-member>inputType</dfn></dt> |
| 82 | + <dd> |
| 83 | + Initializes the <code>inputType</code> attribute of the InputEvent object. |
| 84 | + </dd> |
| 85 | + </dl> |
| 86 | + |
| 87 | + <h4 id="events-inputevent-event-order">Input Event Order</h4> |
| 88 | + |
| 89 | + The input events defined in this specification MUST occur in a set order |
| 90 | + relative to one another. |
| 91 | + |
| 92 | + ++---+-------------+---------------------------------------------------+ |
| 93 | + =| # | Event Type | Notes | |
| 94 | + +---+-------------+---------------------------------------------------+ |
| 95 | + +| 1 | beforeinput | | |
| 96 | + +| | | <em>DOM element is updated</em> | |
| 97 | + +| 2 | input | | |
| 98 | + ++---+-------------+---------------------------------------------------+ |
| 99 | + |
| 100 | + <h4 id="events-input-types">Input Event Types</h4> |
| 101 | + |
| 102 | + <h5 id="event-type-beforeinput"><dfn>beforeinput</dfn></h5> |
| 103 | + |
| 104 | + ++------------------+--------------------------------------------------------------------------------------+ event-definition |
| 105 | + =| % | | |
| 106 | + +------------------+--------------------------------------------------------------------------------------+ |
| 107 | + +| Type | <strong><code>beforeinput</code></strong> | |
| 108 | + +| Interface | {{InputEvent}} | |
| 109 | + +| Sync / Async | Sync | |
| 110 | + +| Bubbles | Yes | |
| 111 | + +| Trusted Targets | <code>Element</code> (specifically: control types such as | |
| 112 | + | | <code>HTMLInputElement</code>, etc.) or any <code>Element</code> with | |
| 113 | + | | <code>contenteditable</code> attribute enabled | |
| 114 | + +| Cancelable | Yes | |
| 115 | + +| Composed | Yes | |
| 116 | + +| Default action | Update the DOM element | |
| 117 | + +| Context<br> | <ul> | |
| 118 | + | (trusted events) | <li>{{Event}}.{{Event/target}} : <a>event target</a> that is about to be updated</li>| |
| 119 | + | | <li>{{UIEvent}}.{{UIEvent/view}} : <a><code>Window</code></a></li> | |
| 120 | + | | <li>{{UIEvent}}.{{UIEvent/detail}} : <code>0</code></li> | |
| 121 | + | | <li>{{InputEvent}}.{{InputEvent/data}} : the string containing the data that will | |
| 122 | + | | be added to the element, which MAY be <code>null</code> if the content will | |
| 123 | + | | be deleted</li> | |
| 124 | + | | <li>{{InputEvent}}.{{InputEvent/isComposing}} : <code>true</code> if this event is | |
| 125 | + | | dispatched during a <a href="#keys-dead">dead key</a> sequence or while an | |
| 126 | + | | <a>input method editor</a> is active (such that | |
| 127 | + | | <a href="#events-compositionevents">composition events</a> are being dispatched);| |
| 128 | + | | <code>false</code> otherwise.</li> | |
| 129 | + | | </ul> | |
| 130 | + ++------------------+--------------------------------------------------------------------------------------+ |
| 131 | + |
| 132 | + A <a>user agent</a> MUST dispatch this event when the DOM is about |
| 133 | + to be updated. |
| 134 | + |
| 135 | + <h5 id="event-type-input"><dfn>input</dfn></h5> |
| 136 | + |
| 137 | + ++------------------+--------------------------------------------------------------------------------------+ event-definition |
| 138 | + =| % | | |
| 139 | + +------------------+--------------------------------------------------------------------------------------+ |
| 140 | + +| Type | <strong><code>input</code></strong> | |
| 141 | + +| Interface | {{InputEvent}} | |
| 142 | + +| Sync / Async | Sync | |
| 143 | + +| Bubbles | Yes | |
| 144 | + +| Trusted Targets | <code>Element</code> (specifically: control types such as | |
| 145 | + | | <code>HTMLInputElement</code>, etc.) or any <code>Element</code> with | |
| 146 | + | | <code>contenteditable</code> attribute enabled | |
| 147 | + +| Cancelable | No | |
| 148 | + +| Composed | Yes | |
| 149 | + +| Default action | None | |
| 150 | + +| Context<br> | <ul> | |
| 151 | + | (trusted events) | <li>{{Event}}.{{Event/target}} : <a>event target</a> that was just updated</li> | |
| 152 | + | | <li>{{UIEvent}}.{{UIEvent/view}} : <a><code>Window</code></a></li> | |
| 153 | + | | <li>{{UIEvent}}.{{UIEvent/detail}} : <code>0</code></li> | |
| 154 | + | | <li>{{InputEvent}}.{{InputEvent/data}} : the string containing the data that has | |
| 155 | + | | been added to the element, which MAY be the <a>empty string</a> if the content | |
| 156 | + | | has been deleted</li> | |
| 157 | + | | <li>{{InputEvent}}.{{InputEvent/isComposing}} : <code>true</code> if this event is | |
| 158 | + | | dispatched during a <a href="#keys-dead">dead key</a> sequence or while an | |
| 159 | + | | <a>input method editor</a> is active (such that | |
| 160 | + | | <a href="#events-compositionevents">composition events</a> are being dispatched);| |
| 161 | + | | <code>false</code> otherwise.</li> | |
| 162 | + | | </ul> | |
| 163 | + ++------------------+--------------------------------------------------------------------------------------+ |
| 164 | + |
| 165 | + A <a>user agent</a> MUST dispatch this event immediately after the |
| 166 | + DOM has been updated. |
| 167 | + |
| 168 | + |
0 commit comments