Skip to content

Commit

Permalink
refactor(Modal): use mask-image for overflow indicator (#15734)
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Feb 13, 2024
1 parent 77df181 commit ffc385b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 63 deletions.
19 changes: 7 additions & 12 deletions packages/react/src/components/ComposedModal/ComposedModal.tsx
Expand Up @@ -62,18 +62,13 @@ export const ModalBody = React.forwardRef<HTMLDivElement, ModalBodyProps>(
: {};

return (
<>
<div
className={contentClass}
{...hasScrollingContentProps}
{...rest}
ref={ref}>
{children}
</div>
{hasScrollingContent && (
<div className={`${prefix}--modal-content--overflow-indicator`} />
)}
</>
<div
className={contentClass}
{...hasScrollingContentProps}
{...rest}
ref={ref}>
{children}
</div>
);
}
);
Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/components/Modal/Modal.tsx
Expand Up @@ -488,9 +488,6 @@ const Modal = React.forwardRef(function Modal(
{...hasScrollingContentProps}>
{children}
</div>
{hasScrollingContent && (
<div className={`${prefix}--modal-content--overflow-indicator`} />
)}
{!passiveModal && (
<ButtonSet className={footerClasses} aria-busy={loadingActive}>
{Array.isArray(secondaryButtons) && secondaryButtons.length <= 2
Expand Down
58 changes: 10 additions & 48 deletions packages/styles/scss/components/modal/_modal.scss
Expand Up @@ -350,60 +350,22 @@
.#{$prefix}--modal-scroll-content {
// Required to accommodate focus outline's negative offset when scrolling in Chrome
border-block-end: 2px solid transparent;
mask-image: linear-gradient(
to bottom,
$layer calc(100% - 80px),
transparent calc(100% - 48px),
transparent 100%
),
linear-gradient(to left, $layer 0, 16px, transparent 16px),
linear-gradient(to right, $layer 0, 2px, transparent 2px),
linear-gradient(to top, $layer 0, 2px, transparent 2px);
}

// Required so overflow-indicator disappears at end of content
.#{$prefix}--modal-scroll-content > *:last-child {
padding-block-end: $spacing-06;
}

.#{$prefix}--modal-content--overflow-indicator {
position: absolute;
background: $layer;
block-size: convert.to-rem(48px);
grid-column: 1/-1;
grid-row: 2/-2;
inline-size: calc(100% - $spacing-05);
inset-block-end: 0;
inset-inline-start: 0;
pointer-events: none;

&::before {
position: absolute;
background-image: linear-gradient(to bottom, transparent, $layer);
block-size: convert.to-rem(32px);
content: '';
inline-size: 100%;
inset-block-start: -32px;
pointer-events: none;
}
}

// Safari-only media query
// won't appear correctly with CSS custom properties
// see: code snippet and tabs overflow indicators
@media not all and (min-resolution >= 0.001dpcm) {
@supports (-webkit-appearance: none) and (stroke-color: transparent) {
.#{$prefix}--modal-content--overflow-indicator {
background-image: linear-gradient(to bottom, rgba($layer, 0), $layer);
}
}
}

.#{$prefix}--modal-content:focus
~ .#{$prefix}--modal-content--overflow-indicator {
margin: 0 2px 2px;
}

@media screen and (-ms-high-contrast: active) {
.#{$prefix}--modal-scroll-content > *:last-child {
padding-block-end: 0;
}

.#{$prefix}--modal-content--overflow-indicator {
display: none;
}
}

// -----------------------------
// Modal footer
// -----------------------------
Expand Down

0 comments on commit ffc385b

Please sign in to comment.