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: indentation level of modals #3515

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/tasty-readers-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/application-components': patch
---

Use correct indentation level for modals rendered in portals container
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { useState, useCallback } from 'react';
import { useState, useCallback, useEffect } from 'react';
import { PORTALS_CONTAINER_ID } from '@commercetools-frontend/constants';

const PORTALS_CONTAINER_MUTATION_TRIGGER = 'portals-container-mutation-trigger';

const useModalState = (isInitiallyOpen = false) => {
const [isModalOpen, setIsModalOpen] = useState(isInitiallyOpen);

// This is a workaround to make sure the portals container's Mutation Observer picks up a DOM mutation when the modal is opened
// This is neccessary to make sure the modal stacking layer's indentation level is correctly calculated
useEffect(() => {
if (isModalOpen) {
const newDiv = document.createElement('div');
newDiv.dataset.role = PORTALS_CONTAINER_MUTATION_TRIGGER;
const portalsContainer = document.querySelector(
`div#${PORTALS_CONTAINER_ID}`
);
portalsContainer?.appendChild(newDiv);
} else {
const triggers = document.querySelectorAll(
`div[data-role="${PORTALS_CONTAINER_MUTATION_TRIGGER}"]`
);
triggers.forEach((trigger) => trigger.remove());
}
}, [isModalOpen]);

const openModal = useCallback(() => setIsModalOpen(true), []);
const closeModal = useCallback(() => setIsModalOpen(false), []);

Expand Down
Loading