ScrollShadow
Shadows that reveal scrollable overflow at container edges
Usage
import {ScrollShadow} from "@peakui/react";A region with no focusable content should also pass tabIndex={0} so keyboard users can scroll it (WCAG 2.1.1).
Examples
Orientation
orientation picks the scroll axis; the fade follows it.
Hide Scroll Bar
Shadow Size
size sets the fade gradient length in pixels.
Offset
The start fade stays at zero until offset pixels are scrolled.
Visibility Change
onVisibilityChange reports the current edge state while the user scrolls.
Without Overflow
Content that fits keeps both fades at zero.
Controlled Visibility
visibility pins the shadows; isEnabled={false} turns detection off.
RTL
In a right-to-left context the horizontal fade flips to the matching edge.
On A Surface
Customization
Tailwind CSS
{/* In auto mode the root owns the `animation` property for the scroll-driven fade.
An `animate-*` utility on the same element would replace it and kill the fade —
animate a wrapper instead. */}
<ScrollShadow className="max-h-[240px] rounded-xl border p-4">Content</ScrollShadow>Global CSS
@layer components {
.scroll-shadow {
@apply rounded-xl border;
}
.scroll-shadow--hide-scrollbar {
--scroll-shadow-scrollbar-size: 0px;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The ScrollShadow component uses these CSS classes (view source styles):
Base Classes
.scroll-shadow- Base component styles
Orientation Classes
.scroll-shadow--vertical- Vertical scrolling (default).scroll-shadow--horizontal- Horizontal scrolling
Variant Classes
.scroll-shadow--fade- Fade mask effect (default)
Modifier Classes
.scroll-shadow--hide-scrollbar- Hides the native scrollbar
Slots
[data-slot="scroll-shadow"]- The root element
CSS Variables
| Variable | Purpose |
|---|---|
--scroll-shadow-size | Fade gradient size (default 40px), set from the size prop |
--scroll-shadow-offset | Scroll distance before the fade starts (default 0px), set from the offset prop |
--scroll-shadow-scrollbar-size | Solid mask gutter reserving space for the native scrollbar (10px, 0px when hideScrollBar) |
Interactive States
The component supports both CSS pseudo-classes and data attributes:
- Top overflow:
[data-top-scroll="true"] - Bottom overflow:
[data-bottom-scroll="true"] - Both vertical edges:
[data-top-bottom-scroll="true"] - Left overflow:
[data-left-scroll="true"] - Right overflow:
[data-right-scroll="true"] - Both horizontal edges:
[data-left-right-scroll="true"] - Orientation:
[data-orientation="vertical" | "horizontal"] - Shadow mode:
[data-scroll-shadow-mode="auto" | "manual"]—"manual"whenvisibilityis controlled orisEnabledisfalse
API Reference
ScrollShadow
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "vertical" | "horizontal" | "vertical" | The scroll direction |
variant | "fade" | "fade" | The visual shadow effect |
size | number | 40 | The shadow gradient size in pixels |
offset | number | 0 | The scroll offset before showing shadows, in pixels |
hideScrollBar | boolean | false | Whether to hide the native scrollbar |
isEnabled | boolean | true | Whether scroll shadow detection is enabled |
visibility | "auto" | "both" | "top" | "bottom" | "left" | "right" | "none" | "auto" | Controlled shadow visibility; any value besides "auto" opts out of the scroll-driven mask and its always-on stacking context |
onVisibilityChange | (visibility: ScrollShadowVisibility) => void | - | Called when the shadow visibility changes |
className | string | - | Additional classes |
children | ReactNode | - | The scrollable content |
Every other attribute of a <div> is accepted.