Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/react modal default #559

Merged
merged 4 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ Note: this component requires custom styles. These styles can be imported from t
### Parameters

* `onClose` **[Function][139]** A handler for closing the modal. May be triggered via the close button, and outside click, or a key press.
* `className` **([String][138] | [Object][144])** Additional class to append to the base class of the modal (modal-inner). See [React Modal's style documentation][167] for more details. (optional, default `""`)
* `overlayClassName` **([String][138] | [Object][144])** Additional class to append to the base class of the modal overlay (modal-fade-screen). See [React Modal's style documentation][167] for more details. (optional, default `""`)
* `isOpen` **[Boolean][140]** A flag for showing the modal. (optional, default `true`)
* `preventClose` **[Boolean][140]** A flag for preventing the modal from being closed (close button, escape, or overlay click). (optional, default `false`)

Expand Down Expand Up @@ -2011,3 +2013,5 @@ function MyView () {
[165]: https://github.com/reactjs/react-modal

[166]: https://github.com/reactjs/react-modal/issues/25

[167]: http://reactcommunity.org/react-modal/styles/classes/#for-the-content-and-overlay
15 changes: 14 additions & 1 deletion migration-guides/v7.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This version contains the following breaking changes:
13. `<FlashMessageContainer />` component invokes `onDismiss` with redux-flash message object and allows message-specific overrides
14. `<Button />` and `<SubmitButton />` now accept a forwarded ref
15. `<Modal />` no longer overwrites the default modal or overlay class
16. `<Modal />` targets #root instead of the body

The required changes for each item are detailed below.

Expand Down Expand Up @@ -367,4 +368,16 @@ Prior to v7, passing in a custom class name to the modal would override the defa
// add additional custom styles
}
```
This logic applies to both the `className` and `overlayClassName` props, whether the use passes in a string or an object.
This logic applies to both the `className` and `overlayClassName` props, whether the use passes in a string or an object.

## 16. `<Modal />` targets #root instead of the body
To make the Modal component more accessible, content needs to be hidden while the modal is open. `react-modal` accomplishes this by applying this attribute to the `appElement`, defined by the user. Previously, this library was relying on `body` to serve as that element. However, Firefox will ignore _all_ content when the body has that applied. Now, the `#root` selector is used.

This should work seamlessly with any project that started from the LPL client template. If for whatever reason your application does **not** have an element with an id of `root`, then you can either add that id to one of the top-most elements or you can override the `appElement` prop with a target that's appropriate for your application. E.g.,

```jsx
function LocalModal(props) {
const el = document.querySelector('#main')
return <Modal appElement={el} {...props} />
}
```
8 changes: 6 additions & 2 deletions src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import classnames from 'classnames'
* @name Modal
* @type Function
* @param {Function} onClose - A handler for closing the modal. May be triggered via the close button, and outside click, or a key press.
* @param {String|Object} [className=""] - Additional class to append to the base class of the modal (modal-inner). See [React Modal's style documentation](http://reactcommunity.org/react-modal/styles/classes/#for-the-content-and-overlay) for more details.
* @param {String|Object} [overlayClassName=""] - Additional class to append to the base class of the modal overlay (modal-fade-screen). See [React Modal's style documentation](http://reactcommunity.org/react-modal/styles/classes/#for-the-content-and-overlay) for more details.
* @param {Boolean} [isOpen=true] - A flag for showing the modal.
* @param {Boolean} [preventClose=false] - A flag for preventing the modal from being closed (close button, escape, or overlay click).
*
Expand Down Expand Up @@ -56,6 +58,8 @@ const propTypes = {
}

const defaultProps = {
className: "",
overlayClassName: "",
isOpen: true,
preventClose: false,
}
Expand All @@ -64,7 +68,7 @@ function getRootElement() {
// Skip in SSR mode
if (isServer()) return
// eslint-disable-next-line no-undef
return window.document.querySelector('body')
return window.document.querySelector('#root')
}

function wrapClassName(base, additional) {
Expand All @@ -88,7 +92,7 @@ function Modal({ isOpen, onClose, preventClose, children, className, overlayClas
overlayClassName={wrapClassName("modal-fade-screen", overlayClassName)}
bodyOpenClassName="modal-open"
appElement={getRootElement()}
ariaHideApp={isServer()} // Opt out of setting appElement on the server.
ariaHideApp={!isServer()} // Opt out of manipulating appElement on the server.
shouldCloseOnEsc={canClose}
shouldCloseOnOverlayClick={canClose}
{...rest}
Expand Down