Bug 165004 - The event order of keydown/keyup events and composition events are wrong on macOS
Summary: The event order of keydown/keyup events and composition events are wrong on m...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: WebKit Nightly Build
Hardware: Macintosh macOS 10.12
: P2 Normal
Assignee: Nobody
URL: https://dvcs.w3.org/hg/d4e/raw-file/t...
Depends on:
Reported: 2016-11-21 00:18 PST by Masayuki Nakano
Modified: 2018-12-18 10:30 PST (History)
6 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Masayuki Nakano 2016-11-21 00:18:41 PST
I tested this on:

* Safari Technology Preview Release 18 (Safari 10.1, WebKit 12603.1.12)
* Safari Version 10.0.1 (12602.


1. Load https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html
2. Change active keyboard layout to "Hiragana" of Japanese IME
3. Type "a" key of ANSI keyboard layout mapping

Expected Result:

event order should be:

1. keydown
2. compositionstart
3. compositionupdate
4. input
5. keyup

Actual Result:

1. compositionstart
2. compositionupdate
3. input
4. keydown
5. keyup

This is really different from the spec:

Google Chrome works as expected. Firefox doesn't fire keyup event since it's traditional behavior <https://bugzil.la/354358> but the order is correct.
Comment 1 Alexey Proskuryakov 2016-11-21 10:49:28 PST
IIRC this is intentional, to match IE. That consideration may no longer be important.
Comment 2 Masayuki Nakano 2016-11-21 22:55:28 PST
(In reply to comment #1)
> IIRC this is intentional, to match IE.

Do you mean, it's IE for Mac? Both IE 11 and Edge on Win10 work same as Chromium (i.e., conforming to UI Events).
Comment 3 Alexey Proskuryakov 2016-11-23 00:56:02 PST
Windows; I think that IE 6 was the latest at the time.
Comment 4 Diogo Franco 2018-04-22 22:27:55 PDT
This is also causing problems when trying to rely on the `isComposing` property of `KeyboardEvent` and `InputEvent`. The Enter key that accepts the IME input will be sent with `isComposing === false`, because Safari is sending events out of order, and `keydown`/`input` are being sent after `compositionend`.

This makes comparing `keyCode === 229` the only reliable way to detect whether IME is being used or not, even though modern APIs are available, because they are giving the wrong results.
Comment 5 Diogo Franco 2018-04-22 22:30:19 PDT
See https://www.w3.org/TR/uievents/#events-composition-key-events and https://www.w3.org/TR/uievents/#events-composition-input-events for the spec. It is very specific that the `keydown` event that exits composition _must_ be sent with `isComposing === true`, but Safari sends them with `isComposing === false`.