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

Fix/scroll behind modals #610

Merged
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
8 changes: 8 additions & 0 deletions src/core/modal.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const modalSlice = createSlice({
initialState: { modalIds: [] },
reducers: {
openModal(state: StateProps, action: PayloadProps) {
// Disables background scrolling whilst the Modal is open
if (typeof window && window.document) {
document.body.style.overflow = "hidden";
}
// If there is a modalid in the payload, and if this modalid is not saved
// then save the modalid
if (
Expand All @@ -66,6 +70,8 @@ const modalSlice = createSlice({
}
},
closeModal(state: StateProps, action: PayloadProps) {
// Enables background scrolling to use when Modal is closed
document.body.style.overflow = "";
const modalId = state.modalIds.pop();
if (state.modalIds.indexOf(action.payload.modalId) > -1) {
state.modalIds.splice(
Expand All @@ -79,6 +85,8 @@ const modalSlice = createSlice({
}
},
closeLastModal(state: StateProps) {
// Enables background scrolling to use when Modal is closed
document.body.style.overflow = "";
const modalId = state.modalIds.pop();
if (modalId) {
removeModalIdFromUrl(state);
Expand Down
12 changes: 6 additions & 6 deletions src/core/utils/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ function Modal({
<div
className="modal-backdrop"
style={{
// some elements are designed with z-index which means they pop up over the modal
// so I add 10 to the z-index of the modal
// the index of the modalid is used, so the newest modal is always on top of
// Some elements are designed with z-index which means they pop up over the modal
// so we add 20 to the z-index of the modal (20 is the highest z-index - header).
// The index of the modalid is used, so the newest modal is always on top of
// the remaining modals
zIndex: modalIds.indexOf(modalId) + 10
zIndex: modalIds.indexOf(modalId) + 20
}}
onClick={() => {
close();
Expand All @@ -98,7 +98,7 @@ function Modal({
data-cy={dataCy}
style={{
// same as comment above
zIndex: modalIds.indexOf(modalId) + 11
zIndex: modalIds.indexOf(modalId) + 21
}}
>
<div
Expand All @@ -114,7 +114,7 @@ function Modal({
}`}
style={{
// same as comment above
zIndex: modalIds.indexOf(modalId) + 10
zIndex: modalIds.indexOf(modalId) + 20
}}
aria-label={closeModalAriaLabelText}
onClick={() => {
Expand Down
Loading