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

[@mantine/core] Modal: Overlay respects scrollbar #2669

Merged
merged 1 commit into from Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 51 additions & 47 deletions src/mantine-core/src/Modal/Modal.tsx
Expand Up @@ -214,56 +214,13 @@ export function Modal(props: ModalProps) {
}}
>
{(transitionStyles) => (
<Box id={baseId} className={cx(classes.root, className)} {...others}>
<div
className={classes.inner}
onKeyDownCapture={(event) => {
const shouldTrigger =
(event.target as any)?.getAttribute('data-mantine-stop-propagation') !== 'true';
shouldTrigger && event.key === 'Escape' && closeOnEscape && onClose();
}}
ref={focusTrapRef}
>
<Paper<'div'>
className={classes.modal}
shadow={shadow}
p={padding}
radius={radius}
role="dialog"
aria-labelledby={titleId}
aria-describedby={bodyId}
aria-modal
tabIndex={-1}
style={transitionStyles.modal}
unstyled={unstyled}
>
{(title || withCloseButton) && (
<div className={classes.header}>
<Text id={titleId} className={classes.title}>
{title}
</Text>

{withCloseButton && (
<CloseButton
iconSize={16}
onClick={onClose}
aria-label={closeButtonLabel}
className={classes.close}
/>
)}
</div>
)}

<div id={bodyId} className={classes.body}>
{children}
</div>
</Paper>
<>
<Box id={baseId} className={cx(classes.root, className)} {...others}>
<div style={transitionStyles.overlay}>
<Overlay
className={classes.overlay}
sx={{ position: 'fixed' }}
zIndex={0}
onMouseDown={() => closeOnClickOutside && onClose()}
blur={overlayBlur}
color={
overlayColor ||
Expand All @@ -273,8 +230,55 @@ export function Modal(props: ModalProps) {
unstyled={unstyled}
/>
</div>
</div>
</Box>
<div
role="presentation"
className={classes.inner}
onClick={() => closeOnClickOutside && onClose()}
onKeyDown={(event) => {
const shouldTrigger =
(event.target as any)?.getAttribute('data-mantine-stop-propagation') !== 'true';
shouldTrigger && event.key === 'Escape' && closeOnEscape && onClose();
}}
ref={focusTrapRef}
>
<Paper<'div'>
className={classes.modal}
shadow={shadow}
p={padding}
radius={radius}
role="dialog"
aria-labelledby={titleId}
aria-describedby={bodyId}
aria-modal
tabIndex={-1}
style={transitionStyles.modal}
unstyled={unstyled}
onClick={(event) => event.stopPropagation()}
>
{(title || withCloseButton) && (
<div className={classes.header}>
<Text id={titleId} className={classes.title}>
{title}
</Text>

{withCloseButton && (
<CloseButton
iconSize={16}
onClick={onClose}
aria-label={closeButtonLabel}
className={classes.close}
/>
)}
</div>
)}

<div id={bodyId} className={classes.body}>
{children}
</div>
</Paper>
</div>
</Box>
</>
)}
</GroupedTransition>
</OptionalPortal>
Expand Down