Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

focus() on focused element should not fire focus event #2621

Closed
eps1lon opened this issue Jun 25, 2019 · 2 comments · Fixed by #2700
Closed

focus() on focused element should not fire focus event #2621

eps1lon opened this issue Jun 25, 2019 · 2 comments · Fixed by #2700

Comments

@eps1lon
Copy link
Contributor

eps1lon commented Jun 25, 2019

Basic info:

  • Node.js version: 10.15.2
  • jsdom version: 15.1.

Minimal reproduction case

const { JSDOM } = require("jsdom");

const { window: { document } } = new JSDOM(`
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <div id="app"><button>Hello, Dave</button></div>
  </body>
</html>
`);

function handleEvent(event) {
  console.log(`${event.type} event`, event.target);
}

const button = document.querySelector('button');
button.addEventListener('focus', handleEvent);

button.focus();
button.focus();

https://repl.it/@eps1lonExists/SimpleUnfoldedSequence

How does similar code behave in browsers?

Repeated focus does not fire focus event. It seems like this is matching

If new focus target is the currently focused area of a top-level browsing context, then return.

-- https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps

which isn't implemented by jsdom.

https://codesandbox.io/s/repeated-imperative-focus-2gftr

Misc

Would it be sufficient to check if previous === this and return if this is true after

const previous = this._ownerDocument._lastFocusedElement;

? Couldn't find an existing test in https://github.com/web-platform-tests/wpt/tree/master/html/interaction/focus so I would need to add a new one to the upstream folder too, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants