summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/form-associated/label-delegatesFocus.html
blob: 67f4f61e495af9fbff03e80be9cec34bcf0add8d (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
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=1300587">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<form>
  <label for=custom>label</label>
  <my-custom-element id=custom></my-custom-element>
</form>

<script>
class MyCustomElement extends HTMLElement {
  static formAssociated = true;
  constructor() {
    super();
    const root = this.attachShadow({
      delegatesFocus: true,
      mode: 'open'
    });
    root.appendChild(document.createElement('input'));
  }
};
customElements.define('my-custom-element', MyCustomElement);

window.onload = () => {
  promise_test(async () => {
    const label = document.querySelector('label');
    const customElement = document.querySelector('my-custom-element');
    const input = customElement.shadowRoot.querySelector('input');
    await test_driver.click(label);
    assert_equals(document.activeElement, customElement);
    assert_equals(customElement.shadowRoot.activeElement, input);
  }, `Clicking on a label for a form associated custom element with delegatesFocus should focus the custom element's focus delegate.`);
};
</script>