Loading...
closeBtn.addEventListener('click', () => {
menu.hidePopover();
saveMenuState();
});closeBtn.addEventListener('click', () => menu.hidePopover());
menu.addEventListener('toggle', (e) => {
if (e.newState === 'closed') saveMenuState();
});The toggle event fires for Esc and outside clicks too, so cleanup runs however the popover closes.
hidePopover(), not by setting display: none or removing the popover attribute.toggle event with newState 'closed', so Esc and outside clicks are handled too.popover attribute, otherwise the call throws.Give the button popovertarget with the popover's id and popovertargetaction='hide'.
Popovers with popover='auto' close on outside clicks and Esc. Use popover='manual' to close them only from code or buttons.