You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A change introduced in 34.4.0 was to add support for useOnEscapePress to bind events to specific elements instead of just the document root (and to implement that new functionality in the useOverlay hook):
#18244eab65e5 Thanks @siddharthkp! - Overlay: Attach escape handler to overlay container instead of document to fix stopPropagation
This makes sense, because the events need to be bound to the overlay container so that the overlay can stopPropogation and keep its events contained.
However, this hook is using a global function with a global array of event handlers, even with the element-bound events. So when an escape event is triggered on a top-level overlay, it still calls every escape event handler ever registered:
An example of the undesirable behavior that this bug causes is visible in the Nested Overlays story:
Click the dropdown arrow next to "Star"
Click "+ Create List"
Press Escape
Only the top overlay should close, but both do instead
Click the dropdown arrow next to "Star" again
Both overlays open in incorrect order because the top overlay was never cleaned up properly
I see two possible ways to fix this:
For element-bound useOnEscapePress events, bind/unbind the passed handler function directly. This seems simple but I'm not sure why the behavior is the way it is in the first place - there may be a reason for it. Example of this change:
The text was updated successfully, but these errors were encountered:
iansan5653
changed the title
Element-bound 'escape' events with useOnEscapePress are triggering all escape events
Element-bound events with useOnEscapePress are triggering all escape events globally
Feb 10, 2022
A change introduced in
34.4.0
was to add support foruseOnEscapePress
to bind events to specific elements instead of just the document root (and to implement that new functionality in theuseOverlay
hook):This makes sense, because the events need to be bound to the overlay container so that the overlay can
stopPropogation
and keep its events contained.However, this hook is using a global function with a global array of event handlers, even with the element-bound events. So when an escape event is triggered on a top-level overlay, it still calls every escape event handler ever registered:
react/src/hooks/useOnEscapePress.ts
Lines 3 to 19 in 96473f3
An example of the undesirable behavior that this bug causes is visible in the Nested Overlays story:
I see two possible ways to fix this:
useOnEscapePress
events, bind/unbind the passed handler function directly. This seems simple but I'm not sure why the behavior is the way it is in the first place - there may be a reason for it. Example of this change:useOnEscapePress
for global (root-bound) events, and just bind the escape event using react's nativeonKeyPress
property instead.cc @siddharthkp @mattcosta7
The text was updated successfully, but these errors were encountered: