api.jquery.com icon indicating copy to clipboard operation
api.jquery.com copied to clipboard

Add reusable note to blur, focusout, focusin, focus pages

Open dmethvin opened this issue 8 years ago • 11 comments

See https://github.com/jquery/jquery/issues/3123

How about something like this?

Note: Use of focus-related events are complicated by several factors. On Internet Explorer, focus and blur are asynchronous and do not occur at the point where the .focus() method is called in your code. The focusout and focusin events are implemented inconsistently across browsers and not implemented at all on Firefox, although jQuery simulates the event. Code should not depend on the order of focusin and focusout events relative to focus and blur because it varies across browsers. On all platforms, focusout on the previously focused element (if any) will always occur before focusin on the new one, and blur occurs before focus.

dmethvin avatar May 17 '16 12:05 dmethvin

blur and focusout will occur on the previous element (if any) before focus and focusin occur on the newly focused element

We can only guarantee blur will happen before focus and focusout before focusin. The spec, for instance, mandates that focusin happens before blur and IE 11 follows that.

mgol avatar May 17 '16 12:05 mgol

The last sentence sort of replies to what I posted above but the previous one suggests something else. I'd rephrase it.

mgol avatar May 17 '16 12:05 mgol

Agreed, we can't guarantee that. Edited.

dmethvin avatar May 18 '16 12:05 dmethvin

Hey @dmethvin, In the last sentence, you can probably drop the first "relative" because it's redundant: "Code should not depend on the order of focusin and focusout events relative to focus and blur…"

kswedberg avatar May 18 '16 12:05 kswedberg

Changed! There's a "fewer relatives" mother-in-law joke in here somewhere.

dmethvin avatar May 18 '16 12:05 dmethvin

not implemented at all on Firefox - not in Firefox?

Also, I'd like the text to say focusout will happen before focusin and blur before focus if possible as we do guarantee that.

mgol avatar May 21 '16 19:05 mgol

Agreed, updated to reflect that @mgol.

dmethvin avatar May 23 '16 15:05 dmethvin

Thanks, the note looks good. I only have a grammar question: shouldn't it say in Firefox instead of on Firefox & In Internet Explorer instead of On Internet Explorer? Or have I been using English incorrectly? ;)

mgol avatar May 23 '16 15:05 mgol

Sorry, i just got to this in my inbox! I think you could use on if you think of a browser as a platform or in as an environment. Either works for me. If you think you use English incorrectly, you should see me with French or Spanish.

dmethvin avatar Jun 02 '16 22:06 dmethvin

OK, thanks for an explanation, that captures it nicely. I seem to think of a browser as an environment more than a platform so I see where my in comes from. Either works fine. :)

mgol avatar Jun 02 '16 23:06 mgol

Note: due to https://github.com/jquery/jquery/issues/4300, jQuery 4.0 will drop the guarantee that focusin fires before focus & focusout before blur; let's make sure to not document that guarantee. :)

mgol avatar Aug 21 '19 22:08 mgol