question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make showing / hiding cancellable via event listeners

See original GitHub issue

Use 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:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
KittyGiraudelcommented, Apr 20, 2017

You can store the reference to the current function for sure, yes.

const keypressHandler = A11yDialog.prototype._bindKeypress;

A11yDialog.prototype._bindKeypress = function (event) {
  // Capture escape key.
  keypressHandler(event);
}
1reaction
KittyGiraudelcommented, Apr 20, 2017

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.

A11yDialog.prototype._bindKeypress = function (event) {
  // …
}

Does it make sense?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found