3 ms·
> CloseWatcher API > Chrome 120 brings the solution with CloseWatcher, a new API for directly listening and responding to close requests. > watcher.addEventLi
by ggregoire 3y ago
> CloseWatcher API
> Chrome 120 brings the solution with CloseWatcher, a new API for directly listening and responding to close requests.
> watcher.addEventListener("close", () => document.querySelector("#sidebar").classList.remove("open"));
Couldn't they add an HTML attribute onCloseRequest?
Slightly related, I wish there was an attribute "onClickOutside" so we could close modals and dropdown menus without manually adding an event listener on the window and checking if the click wasn't inside the element.
- domenicd 3y agoThe issue with a single global event handler is discussed here: https://github.com/WICG/close-watcher#a-single-event https://github.com/WICG/close-watcher#a-single-event If you use popover="", you get the kind of functionality you're discussing for free. For <dialog>, the discussion is in progress and reaching a conclusion: https://github.com/whatwg/html/issues/9373 https://github.com/whatwg/html/issues/9373