-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(components): style position for
<PortalsContainer>
layout (#2541)
* fix(components): style position for <PortalsContainer> layout * refactor(playground): clean up and improve layout
- Loading branch information
Showing
11 changed files
with
143 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
'@commercetools-frontend/application-components': patch | ||
'@commercetools-frontend/application-shell': patch | ||
--- | ||
|
||
Fix layout issue with modal components when the underlying page has a scrolling position, causing the modal container position to "scroll" with the page position. | ||
|
||
The expected behavior is for the modal page to always be correctly positioned and visible, regardless of the scrolling position of the underlying page. | ||
|
||
To fix that, the `<PortalsContainer>` now uses `position: fixed` when a modal container opens. | ||
|
||
The component now accepts some props to allow consumers to adjust the layout accordingly. However, for Custom Applications everything is pre-configured, so there is no action required. |
68 changes: 57 additions & 11 deletions
68
packages/application-components/src/components/portals-container/portals-container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,64 @@ | ||
import { css } from '@emotion/react'; | ||
import { css, Global } from '@emotion/react'; | ||
import { PORTALS_CONTAINER_ID } from '@commercetools-frontend/constants'; | ||
|
||
type TPortalsContainerProps = { | ||
/** | ||
* The offset value for positioning the container from the top, when opened. | ||
* Usually this is corresponds to the height of the header section. | ||
*/ | ||
offsetTop: string; | ||
/** | ||
* The CSS selector to apply the `overflow: hidden` style to (preventing scrolling) | ||
* when a modal container is open. | ||
*/ | ||
containerSelectorToPreventScrollingOnOpen: string; | ||
/** | ||
* The `z-index` value to apply to the portal container. Default to `10000`. | ||
*/ | ||
zIndex: number; | ||
}; | ||
const defaultProps: Pick< | ||
TPortalsContainerProps, | ||
'offsetTop' | 'containerSelectorToPreventScrollingOnOpen' | 'zIndex' | ||
> = { | ||
offsetTop: '0', | ||
containerSelectorToPreventScrollingOnOpen: 'main', | ||
zIndex: 10000, | ||
}; | ||
|
||
// All modal components expect to be rendered inside this container. | ||
const PortalsContainer = () => ( | ||
<div | ||
id={PORTALS_CONTAINER_ID} | ||
// The container needs a height in order to be tabbable: https://reactjs/react-modal#774 | ||
css={css` | ||
display: flex; | ||
height: 1px; | ||
margin-top: -1px; | ||
`} | ||
/> | ||
const PortalsContainer = (props: TPortalsContainerProps) => ( | ||
<> | ||
<Global | ||
// Apply some global styles, based on the `.ReactModal__Body--open` class. | ||
styles={css` | ||
.ReactModal__Body--open | ||
${props.containerSelectorToPreventScrollingOnOpen} { | ||
overflow: hidden; | ||
} | ||
.ReactModal__Body--open #${PORTALS_CONTAINER_ID} { | ||
position: fixed; | ||
height: calc(100% - ${props.offsetTop}); | ||
width: 100%; | ||
top: ${props.offsetTop}; | ||
bottom: 0; | ||
z-index: ${props.zIndex}; | ||
} | ||
`} | ||
/> | ||
<div | ||
id={PORTALS_CONTAINER_ID} | ||
// The container needs a height in order to be tabbable: https://reactjs/react-modal#774 | ||
css={css` | ||
display: flex; | ||
height: 1px; | ||
margin-top: -1px; | ||
`} | ||
/> | ||
</> | ||
); | ||
PortalsContainer.displayName = 'PortalsContainer'; | ||
PortalsContainer.defaultProps = defaultProps; | ||
|
||
export default PortalsContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { default } from './entry-point'; | ||
export { ApplicationStateMachines } from './entry-point'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3853d77
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
merchant-center-application-kit – ./
mc-custom-applications.vercel.app
merchant-center-application-kit-git-main-commercetools.vercel.app
merchant-center-application-kit-commercetools.vercel.app