Skip to content

Commit

Permalink
Ensure return of focus from modal when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Jun 26, 2023
1 parent 1671c16 commit a689fea
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ function UnforwardedModal(
);

const onOverlayPress: PointerEventHandler< HTMLDivElement > = ( event ) => {
if ( event.target === event.currentTarget ) onRequestClose( event );
if ( event.target === event.currentTarget ) {
// Retains focus within the modal so that `useFocusReturn` works.
event.preventDefault();
onRequestClose( event );
}
};

return createPortal(
Expand Down

0 comments on commit a689fea

Please sign in to comment.