Click-Outside-to-Close Dropdown

A dropdown menu built on a non-modal `<dialog>` that closes when you click anywhere outside it.

A dropdown menu opens on click and closes when the user clicks anywhere outside it. Built on a non-modal <dialog> so it gets keyboard accessibility and using hyperscript's elsewhere modifier for the click-outside behavior.

Example: Click outside the menu to close it
<div class="dropdown">
<button _="on click show the next <dialog/> then halt">Account ▾</button>
<dialog class="dropdown-menu"
    _="on click elsewhere close me
       on keyup[key is 'Escape'] from window close me">
    <a>Profile</a>
    <a>Settings</a>
    <a>Help</a>
    <hr>
    <a>Sign out</a>
</dialog>
</div>
Try It!

Three pieces of hyperscript do all the work: