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 Events | Assignee: | 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
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 | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Ryosuke Niwa
This is the expected behavior.
Rob Snow
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
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