summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/interaction/focus/the-autofocus-attribute/first-when-later.html
blob: 1d64b863a16e8a0745c4f207d5a92e80175ee34f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<meta charset="utf-8">
<title>The first autofocus in the document wins, even if elements are inserted later</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#autofocusing-a-form-control:-the-autofocus-attribute">
<link rel="author" title="Domenic Denicola" href="d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<input autofocus>

<script>
"use strict";

promise_test(async () => {
  const input1 = document.querySelector("input");
  const input2 = document.createElement("input");
  input2.autofocus = true;
  document.body.appendChild(input2);

  await waitUntilStableAutofocusState();
  assert_equals(document.activeElement, input1);
  assert_not_equals(document.activeElement, input2);
}, 'The first autofocus in the document wins, even if elements are inserted later.');
</script>