Bug 243749 - blur and focusout are not fired on document.activeElements when they are removed from the dom
Summary: blur and focusout are not fired on document.activeElements when they are remo...
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 15
Hardware: Unspecified macOS 12
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-09 13:45 PDT by Rob Snow
Modified: 2022-08-24 09:22 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Snow 2022-08-09 13:45:01 PDT
blur and focusout are not fired on document.activeElements when they are removed from the dom

https://jsfiddle.net/snowystinger/87os2az9/15/

When you run the fiddle in Safari, tab to the button and wait for the setTimeout to remove the button from the dom. I would expect focusout and blur listeners to be triggered. I don't expect them to bubble up the tree as they have been removed, but a direct listener on it should be called.

This is also a bug in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=559561

It works as expected in Chrome.
Comment 1 Ryosuke Niwa 2022-08-10 18:38:03 PDT
This is the expected behavior.
Comment 2 Rob Snow 2022-08-11 11:57:22 PDT
Thanks for the quick reply. However, I would argue this is not good behavior.
It makes it very difficult to track and manage focus.

For example, if you have a focus scope that contains focus within it, you need to know when focus leaves it so you can move the focus back inside. A common example of this is a Dialog.

Right now, a blur event is not fired when the active element is removed from the dom, nor is a focus event fired on the body. So it's impossible to tell that focus moved outside of the scope.

https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps
I know this isn't specific about what happens when an active element becomes inert. However, I think it's reasonable to assume that an element becoming inert must lose focus. Therefore, it should go through the unfocusing steps, and then become inert.

If this isn't the case, how would you recommend containing focus.
Comment 3 Rob Snow 2022-08-11 12:44:51 PDT
For more info in other browser engines, see https://bugzilla.mozilla.org/show_bug.cgi?id=559561

As well as open issues in the living spec
https://github.com/whatwg/html/issues/1195
https://github.com/whatwg/html/issues/3162

https://github.com/jsdom/jsdom/issues/2931