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.

[Toast] Ability to remove `document` event listeners

See original GitHub issue

Feature request

Overview

Currently, the Toast package adds an event listener to the document for managing hotkeys internally.

https://github.com/radix-ui/primitives/blob/3e5644edadcded918db177368c3fe9654ce9885f/packages/react/toast/src/Toast.tsx#L169-L170

I’d like the ability to disable this so that I have full control over Toast hotkey handling. One option would be simply passing an empty array to the hotkeys prop. Ideally, Toast would check the length of the hotkey prop before adding an event handler to document and, if hotkey was length 0, then no handler would be added.

Note: the hotkey listeners were implemented using Array#every() which returns true for an empty array.

Who does this impact? Who is this for?

Users of the Toast package.

Additional context

In my application, I have a sophisticated, custom service which is responsible for handling all hotkeys. I’d like to manage toast hotkeys that way.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
benoitgrelardcommented, Jul 21, 2022

Oh ya, just tested. It works the way I thought it did (i.e. it affects other listeners). Your comment made me think that maybe I’ve had a huge misunderstanding of javascript event listeners for several years now 😅.

No you’re right, it’s just that in other places some of these cancellable events we have are custom events we raise, so those wouldn’t affect any other events. In this case we are piggy-backing on the keyboard event so it would.

0reactions
jjenzzcommented, Jul 22, 2022

In this case we are piggy-backing on the keyboard event so it would.

oh, was that a mistake on our part? seems it should be a CustomEvent no?

Read more comments on GitHub >

github_iconTop Results From Across the Web

EventTarget.removeEventListener() - Web APIs | MDN
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.
Read more >
How to handle standard toast events in LWC
Is there a way to capture standard toasts in lwc? constructor() { super(); document.addEventListener('lightning__showtoast', this.
Read more >
window.addEventListener not triggered by simulated events
The first component I tried to test using this was a mixin for detecting clicks outside a component. In order to do this...
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 >
Lightning Web Component(LWC) Toast Messages - SfdcPoint
Lightning Web component LWC Toast Messages.LWC can send a toast notification that pops up to alert users of success, error or warning.
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