summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/resources/focus-page-with-autofocus.html
blob: d498ef633553a7a69799f4d011bbe7c2e403ea20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<body>
  <button id="one">one</button>
  <button id="two" autofocus>two</button>
  <button id="three">three</button>
  <script>
    function messageHandler(e) {
      if (e.data === 'check-active-element') {
        window.requestAnimationFrame(() => {
          let autofocusedButton = document.querySelector('#two');
          e.source.postMessage(document.activeElement === autofocusedButton);
        });
      }
    }

    window.portalHost.onmessage = messageHandler;
    window.onportalactivate = e => {
      let portal = e.adoptPredecessor();
      portal.onmessage = messageHandler;
      document.body.appendChild(portal);
    }
  </script>
</body>