Re: [w3c/uievents] Should an element remain focused and receive key events if it's display:none-ed? (#236)

I did a bit of digging in the HTML spec. I believe the Chrome behavior (dispatch `blur` on an element that becomes `display: none`) is currently required by the HTML Living Standard.

The [focus mixup rule](https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule) says:

> When the designated focused area of the document is removed from that Document in some way (e.g. it stops being a focusable area, it is removed from the DOM, it becomes expressly inert, etc.), designate the Document's viewport to be the new focused area of the document.


The requirements for being a [focusable area](https://html.spec.whatwg.org/multipage/interaction.html#focusable-area) include [being rendered] (https://html.spec.whatwg.org/multipage/rendering.html#being-rendered) for most elements, which requires producing CSS boxes.  Thus a `display:none` element would not be a focusable area. This will run the [focus update steps](https://html.spec.whatwg.org/multipage/interaction.html#focus-update-steps( which dispatch the `blur` event.

This behavior logically makes sense to me, because a `display: none` element can’t be focused in the first place, so an element that becomes `display: none` shouldn’t retain focus, and everything that happens upon loss of focus should happen.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/uievents/issues/236#issuecomment-506991241

Received on Saturday, 29 June 2019 22:21:26 UTC