Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created November 3, 2021 14:44
Show Gist options
  • Select an option

  • Save nolanlawson/ef0cebcb48a5cf958d176056486642cd to your computer and use it in GitHub Desktop.

Select an option

Save nolanlawson/ef0cebcb48a5cf958d176056486642cd to your computer and use it in GitHub Desktop.
delegatesFocus test
<!doctype html>
<html lang=en>
<head>
<title>delegatesFocus test</title>
</head>
<body>
<h1>delegatesFocus test</h1>
<div></div>
<pre></pre>
<script>
const div = document.querySelector('div')
const pre = document.querySelector('pre')
div.attachShadow({
mode: 'open',
delegatesFocus: true
}).innerHTML = `
<input class="first">
<input class="second">
`
div.shadowRoot.querySelector('.second').focus()
div.focus()
pre.innerHTML = 'focused: ' + div.shadowRoot.activeElement?.className
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment