Skip to content

Instantly share code, notes, and snippets.

@stephband
Last active February 5, 2021 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephband/115b0307940989c79c9306ca49f95d4b to your computer and use it in GitHub Desktop.
Save stephband/115b0307940989c79c9306ca49f95d4b to your computer and use it in GitHub Desktop.
Log activeElement on focus
document.addEventListener('focusin', (e) =>
// Sanity check for target being activeElement, should always be true
console.log('focusin', e.target === document.activeElement, document.activeElement)
);
document.addEventListener('focusout', (e) =>
// Sanity check that activeElement is body, should always be true
console.log('focusout', document.body === document.activeElement)
);
@stephband
Copy link
Author

stephband commented Feb 5, 2021

@halitcelik > What I read is that label gets focus but forwards it to input.

Interesting. But look:

<label tabindex="0" for="x" ... >...</label>
<input type="radio" id="x" />

The label gets focus, but hitting enter does not check the radio.

@halitcelik
Copy link

On firefox, if label doesn't have tabindex, it just skips.

@stephband
Copy link
Author

And this doesn't seem to help... the input gets focus before the link, but the label still does not seem to focus the input.

<input type="radio" id="x" />
<a href="#some-other-focusable-thing">...</a>
<label for="x" ... >...</label>

@stephband
Copy link
Author

Yes, on Chrome too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment