When focused element is removed, fire blur event on it
Categories
(Core :: DOM: UI Events & Focus Handling, defect, P2)
Tracking
()
| Webcompat Priority | P2 |
People
(Reporter: enndeakin, Assigned: avandolder)
References
(Blocks 2 open bugs)
Details
(Keywords: webcompat:platform-bug)
Attachments
(3 files, 1 obsolete file)
|
7.28 KB,
patch
|
Details | Diff | Splinter Review | |
|
555 bytes,
text/html
|
Details | |
|
561 bytes,
text/html
|
Details |
| Reporter | ||
Comment 1•16 years ago
|
||
Comment 2•16 years ago
|
||
| Reporter | ||
Comment 3•16 years ago
|
||
Comment 4•16 years ago
|
||
| Reporter | ||
Comment 5•16 years ago
|
||
Comment 6•16 years ago
|
||
Comment 7•16 years ago
|
||
Comment 8•16 years ago
|
||
Comment 9•16 years ago
|
||
| Reporter | ||
Comment 10•16 years ago
|
||
Comment 13•11 years ago
|
||
Comment 14•11 years ago
|
||
Comment 15•11 years ago
|
||
Comment 17•11 years ago
|
||
| Reporter | ||
Comment 18•11 years ago
|
||
| Reporter | ||
Updated•11 years ago
|
Updated•9 years ago
|
Comment 20•8 years ago
|
||
Updated•7 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 23•6 years ago
|
||
This bug is 10 friggin years old. Can someone fix it?
Comment 24•6 years ago
|
||
And I am here after 11 years! and looking for a fix!!! Wonderful :)
Comment 25•6 years ago
|
||
The spec also says that we should fire a blur when "it stops being a focusable area"
It's not clear that this is implied by
[...] designate the Document's viewport to be the new focused area of the document.
As far as I can tell this does not imply that focus update steps should be run though it would certainly be more useful if document.activeElement is updated and a blur event is fired.
See https://github.com/whatwg/html/issues/1195 and https://github.com/whatwg/html/issues/3162 for similar issues in the living standard, and jsdom/jsdom#2931 for the same issue in jsdom.
Comment 27•4 years ago
|
||
I'm running into this bug trying to implement a Focus Scope component that can contain focus within it. Because blur isn't fired for the activeElement before it's removed and because focus isn't fired for the document body when the focus is inevitably lost there, I have some cases where I cannot contain focus within my component.
Example, a Dialog containing focus within it and the Dialog contents get swapped out due to some action thereby removing the activeElement from the dom.
Updated•4 years ago
|
Comment 28•4 years ago
|
||
Setting webcompat priority as P3 as there are no actual site breakage reports for now.
Comment 29•4 years ago
|
||
I mean, it's breaking us. We've done our best to work around it, but we continue to find edge cases. In addition, it's causing a performance hit and causing us to ship more code.
What we've had to do is:
- attach a MutationObserver that watches our entire document (childlist and subtree)
- track focus movement through the entire document as the 'currently focused' element
- when anything is removed from the document, we check if the 'currently focused' element was within the tree that was removed
- fire our own blur event on the removed element
Note, this is async, delayed, and doesn't bubble through the tree before removal. So while we track focus movement through the entire document, everything that needs to care if the focused element blurs must attach a blur listener directly to the element. This does not work great when other libraries interact with ours.
Hope this helps anyone else though looking for a workaround.
Comment 30•4 years ago
|
||
Thanks for the feedback :rsnow.
Hi Hsin-Yi, wonder if it's possible to re-prioritize this, based on the comment 29?
Comment 31•4 years ago
|
||
(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #17)
(display: none case is a separate issue though.)
Yes, the display:none or visibility: hidden case is a different issue which the focus state isn't updated properly at all, we probably could track them separately in bug 1619271. And make this bug focus on missing blur event of element removal.
Comment 32•4 years ago
|
||
Clearing NI - Adam is going to (or already working) on this. Thank you for bringing this again to our attention radar. :)
Updated•4 years ago
|
Comment 33•4 years ago
|
||
The severity field for this bug is relatively low, S3. However, the bug has 4 duplicates.
:avandolder, could you consider increasing the bug severity?
For more information, please visit auto_nag documentation.
| Assignee | ||
Comment 34•4 years ago
|
||
| Assignee | ||
Updated•4 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
| Assignee | ||
Comment 35•4 years ago
|
||
Just as an update for anyone who may be following this bug, there is currently a working-ish implementation of behaviour similar to Chrome's implemented in the linked patch. However, due to the above open spec issues, it's unclear what the standard behaviour should be and therefore we're going to have to wait until that is resolved.
Comment 36•3 years ago
|
||
Adam, the spec issue here seems to have been resolved recently, and we just found out that GitHub hovercards are similarly affected by focusout not firing when an element is hidden/removed (in https://webcompat.com/issues/117240). Could you advise on whether you feel the resolution here will resolve that as well, or if another spec issue is needed to address focusout separately?
| Assignee | ||
Comment 37•3 years ago
|
||
From my understanding of the new focus fixup spec, when an element is removed, blur and focusout events will not be triggered, but instead the document body should be made focused - and that is what this bug will implement.
When an element is hidden, however, blur/focusout should be triggered, and I believe that should be fixed with bug 1810077, although I'm not sure if that addresses the GitHub issue specifically.
Comment 38•2 years ago
|
||
Verified this issue and I am not sure how to treat this. I can see in the console log focus [object HTMLInputElement] followed by blur [object HTMLInputElement]. The errors are pretty much similar in both Chrome and Firefox "Refuse to execute inline event handler...".
Does that mean that it works in both Chrome and Firefox, based on test case ? Also https://webcompat.com/issues/117240 is fixed
Tested with:
Browser / Version: Firefox Nightly 128.0a1 (2024-05-21) (64-bit)
Operating System: Windows 10 PRO x64
Comment 39•2 years ago
|
||
This was fixed in bug 1740989, improved upon in bug 1895870.
Comment 40•2 years ago
|
||
DOM removal right now doesn't fire an event per spec right now.
So let's close as a dupe of bug 1740989. If we want to fire events on dom node removal we can track it when the spec is changed.
Updated•2 years ago
|
Updated•2 years ago
|
Description
•