class DetailsDisclosure extends HTMLElement {
constructor() {
super();
this.mainDetailsToggle = this.querySelector('details');
this.mainDetailsToggle.addEventListener('focusout', this.onFocusOut.bind(this));
}
onFocusOut() {
setTimeout(() => {
if (!this.contains(document.activeElement)) this.close();
})
}
close() {
this.mainDetailsToggle.removeAttribute('open');
this.mainDetailsToggle.querySelector('summary').setAttribute('aria-expanded', false);
}
}
customElements.define('details-disclosure', DetailsDisclosure);