Make showing / hiding cancellable via event listeners
See original GitHub issueUse case: I want to display a form in the dialog. When the user accidentally clicks outside the dialog or on the close button, the dialog closes without warning. I could check in the hide event listener if the user has already entered some data and confirm if they really want to close.
It would be great if I then could just return false in the event listener to cancel the action. Maybe a beforeHide event would also be valuable.
The same can also be applied to the show event, though I guess it won’t be too helpful.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Event.cancelable - Web APIs - MDN Web Docs
If the event is not cancelable, then its cancelable property will be false and the event listener cannot stop the event from occurring....
Read more >Removing an anonymous event listener - Stack Overflow
The easiest way to remove all event listeners for an element is to assign its outerHTML to itself. What this does is send...
Read more >Show and hide divs on click - By. Jeroen Wiersma
When someone clicks the button we want a function to trigger. We can do this by using the .
Read more >Handling Events :: Eloquent JavaScript
Event handlers make it possible to detect and react to events happening in our web page. The addEventListener method is used to register...
Read more >Cancel Events - Egghead.io
In this lesson, we will look at what it means to cancel an event, ... Toggle side panel ... Listen to Events using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You can store the reference to the current function for sure, yes.
Unfortunately you will not be able to override it while keeping its functionality. What you can do is copy it and tweak it the way you want. Here is the current version: https://github.com/edenspiekermann/a11y-dialog/blob/master/a11y-dialog.js#L253-L266.
Does it make sense?