From ee5a4f5d364465cce139a14e5c5b09d72ca3f141 Mon Sep 17 00:00:00 2001 From: "Robert W. Pearce" Date: Fri, 28 Jul 2023 09:07:50 -0400 Subject: [PATCH] fix(430): ESC intermittently not working in Safari There's a weird issue, probably related to Safari's `:focus-visible` behavior or their `` implementation, where the `` element's button doesn't receive focus when it's opened. It could also be a race condition because of the animation. Regardless, let's try listening for `Escape` at the `document` level when we zoom an image. We need to make sure we provide the `useCapture` option and get to the event first so we can intercept it and don't trigger the default `` `Escape` behavior so we can animate zooming out. --- source/Controlled.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Controlled.tsx b/source/Controlled.tsx index f25085db..6b043fd8 100644 --- a/source/Controlled.tsx +++ b/source/Controlled.tsx @@ -3,7 +3,6 @@ import React, { Component, ElementType, ImgHTMLAttributes, - KeyboardEvent, MouseEvent, ReactElement, ReactNode, @@ -153,7 +152,6 @@ class ControlledBase extends Component } {hasImage && elDialogContainer != null && createPortal( - @@ -352,6 +349,7 @@ class ControlledBase extends Component) => { + handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape' || e.keyCode === 27) { e.preventDefault() e.stopPropagation() @@ -585,6 +583,7 @@ class ControlledBase extends Component