Skip to content

Autofocus element in a <dialog> tries to get focus twice #4788

@tkent-google

Description

@tkent-google

The following code shows FOCUS log twice.

<!DOCTYPE html>
<pre></pre>
<dialog>
  <input autofocus onfocus="log()">
  <a href="http://www.google.com/">Help</a>
</dialog>

<script>
function log() {
  document.querySelector('pre').textContent += 'FOCUS\n';
}

document.querySelector('dialog').show();
document.activeElement.blur();
</script>
  1. The HTML parser inserts the input to the document tree, and it posts the autofocus task.
  2. dialog.show() sets focus on the input synchronously.
  3. When the task is executed, the input is focused again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions