Skip to content

Commit

Permalink
Fix SidePanel and Modal issues on Safari (#1498)
Browse files Browse the repository at this point in the history
* Fix the opening animation of SidePanel and Modal

* Prevent page scroll after the SidePanel or Modal is closed

* Add changeset
  • Loading branch information
hris27 authored Apr 5, 2022
1 parent 7e81662 commit 209b35b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-frogs-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed opening animation and unwanted page scroll when closing a `SidePanel` or `Modal` on Safari.
7 changes: 7 additions & 0 deletions packages/circuit-ui/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ export const Modal: ModalComponent<ModalProps> = ({
closeTimeoutMS: TRANSITION_DURATION,
shouldCloseOnOverlayClick: !preventClose,
shouldCloseOnEsc: !preventClose,
/**
* react-modal relies on document.activeElement to return focus after the modal is closed.
* Safari and Firefox don't set it properly on button click (see https://github.com/reactjs/react-modal/issues/858 and https://github.com/reactjs/react-modal/issues/389).
* Returning the focus to document.body or to the focus-root can cause unwanted page scroll.
* Preventing scroll on focus would provide better UX for mouse users and shouldn't cause any side effects for assistive technology users.
*/
preventScroll: true,
...props,
};

Expand Down
7 changes: 7 additions & 0 deletions packages/circuit-ui/components/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ export const SidePanel = ({
htmlOpenClassName: HTML_OPEN_CLASS_NAME,
onRequestClose: onBack || onClose,
portalClassName: PORTAL_CLASS_NAME,
/**
* react-modal relies on document.activeElement to return focus after the modal is closed.
* Safari and Firefox don't set it properly on button click (see https://github.com/reactjs/react-modal/issues/858 and https://github.com/reactjs/react-modal/issues/389).
* Returning the focus to document.body or to the focus-root can cause unwanted page scroll.
* Preventing scroll on focus would provide better UX for mouse users and shouldn't cause any side effects for assistive technology users.
*/
preventScroll: true,
};

const content = (
Expand Down
2 changes: 1 addition & 1 deletion packages/circuit-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react-dates": "^21.2.0",
"react-modal": "^3.8.1",
"react-modal": "^3.14.4",
"react-number-format": "^4.9.1",
"react-popper": "^2.2.5",
"use-latest": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15786,7 +15786,7 @@ react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==

react-modal@^3.8.1:
react-modal@^3.14.4:
version "3.14.4"
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.14.4.tgz#2ca7e8e9a180955e5c9508c228b73167c1e6f6a3"
integrity sha512-8surmulejafYCH9wfUmFyj4UfbSJwjcgbS9gf3oOItu4Hwd6ivJyVBETI0yHRhpJKCLZMUtnhzk76wXTsNL6Qg==
Expand Down

1 comment on commit 209b35b

@vercel
Copy link

@vercel vercel bot commented on 209b35b Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.