document.hasFocus() returns true during focusout event when the document is losing focus
Categories
(Core :: DOM: UI Events & Focus Handling, defect, P3)
Tracking
()
People
(Reporter: xidorn, Unassigned)
References
Details
Attachments
(1 file)
|
312 bytes,
text/html
|
Details |
Steps to reproduce:
- open the attached testcase
- click on a to focus the contenteditable
- click somewhere else in the Firefox UI (to switch the focus from the document)
Expected result:
focusout (sync): false
focusout (async): false
should shows up.
Actual result:
focusout (sync): true
focusout (async): false
should shows up.
While the UI Events spec says focusout is dispatched when the element is about to lose focus, the HTML spec says when the browser context does not has system focus, document.hasFocus() should return false.
It feels to me that if the loss of focus of the element is triggered by loss of focus of the document, the document already loses the focus, and document.hasFocus() should probably return false at that point already. Not sure my interpretation is correct.
Anyway, this behavior is different from Chrome, and could cause issues on sites. (Safari doesn't seem to trigger focusout when the document is losing focus, fwiw.)
Comment 1•5 years ago
|
||
https://w3c.github.io/uievents/#focusout
This event type MUST be dispatched before the element loses focus.
So, Gecko's behavior confirms the spec, but indeed, Chrome returns false from the focusout listener...
It seems that this is related issue on Chrome side:
https://bugs.chromium.org/p/chromium/issues/detail?id=645988
Smaug, WDYH?
Comment 2•5 years ago
|
||
Oops, I forgot to request ni for the previous comment.
Comment 3•5 years ago
|
||
focusin/out events have been a great mess. They used to be implemented correctly in IE, but were then incorrectly implemented in webkit/chrome.
Given that Gecko also has now the odd behavior (to be more compatible with Chrome), I guess returning false during focusout is ok.
Comment 4•5 years ago
|
||
Thank you for the explanation, I think that this can be P3 unless this breaks some web apps.
Description
•