Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
            - /shadow-dom/focus-within-shadow.html - WPT Dashboard Interop Dashboard
 
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:masonf@chromium.org">
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<div id=host>
  <template shadowrootmode=open>
    <button><slot></slot></button>
  </template>
  <span>Content</span>
</div>
<script>
  const host = document.getElementById('host');
  test(() => {
    const shadowButton = host.shadowRoot.querySelector('button');
    shadowButton.focus();
    assert_equals(document.activeElement,host,'nodes within shadow DOM aren\'t exposed');
    host.textContent = 'New Content';
    assert_equals(document.activeElement,host,'Clearing light DOM shouldn\'t clear focus');
  },'Don\'t clear focus within shadow root if light DOM children are cleared');
</script>