Bug 243749

Summary: blur and focusout are not fired on document.activeElements when they are removed from the dom
Product: WebKit Reporter: Rob Snow <rsnow>
Component: UI EventsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Normal CC: ap, cdumez, ntim, rniwa
Priority: P2    
Version: Safari 15   
Hardware: Unspecified   
OS: macOS 12   

Rob Snow
Reported 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.
Attachments
Ryosuke Niwa
Comment 1 2022-08-10 18:38:03 PDT
This is the expected behavior.
Rob Snow
Comment 2 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.
Rob Snow
Comment 3 2022-08-11 12:44:51 PDT
Note You need to log in before you can comment on or make changes to this bug.