Skip to content

Instantly share code, notes, and snippets.

@stephband
Last active February 5, 2021 13:27
Show Gist options
  • Select an option

  • Save stephband/115b0307940989c79c9306ca49f95d4b to your computer and use it in GitHub Desktop.

Select an option

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

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