Scroll Fade
A scrollable container that fades its edges to signal more content along the enabled axis.
Preview
<x-ui.scroll-fade axis="horizontal" class="max-w-md">
<div class="flex gap-3 p-1">
@foreach (range(1, 10) as $i)
<div class="flex h-24 w-32 shrink-0 items-center justify-center rounded-lg border border-border bg-card text-lg font-semibold text-card-foreground">
{{ __('Card') }} {{ $i }}
</div>
@endforeach
</div>
</x-ui.scroll-fade>
Installation
php artisan ui:add scroll-fade
Note
This component ships an Alpine behavior module at
resources/js/ui/scroll-fade.js. Import it once from your bundle so it registers on alpine:init:
import './scroll-fade.js';
Registry contract
php artisan ui:add scroll-fade
writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.
-
resources/views/components/ui/scroll-fade.blade.php -
resources/js/ui/scroll-fade.js
- Registry dependencies
- None — installs on its own.
- Packages
-
composer: jml/brok:^0.2npm: alpinejs
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Scroll Fade (`scroll-fade`)
A scrollable container that fades its edges to signal more content along the enabled axis.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add scroll-fade
```
## Usage
```blade
<x-ui.scroll-fade axis="horizontal" class="max-w-md">
<div class="flex gap-3 p-1">
@foreach (range(1, 10) as $i)
<div class="flex h-24 w-32 shrink-0 items-center justify-center rounded-lg border border-border bg-card text-lg font-semibold text-card-foreground">
{{ __('Card') }} {{ $i }}
</div>
@endforeach
</div>
</x-ui.scroll-fade>
```
## Props
- `axis` (string, default `horizontal`) — Scroll and fade direction: horizontal (default), vertical, or both.
- `hideScrollbar` (bool, default `true`) — Hides the native scrollbar while keeping the region scrollable.
- `intensity` (int, default `1`) — Opacity multiplier for the edge fades.
- `label` (mixed|null, default `null`) — Accessible name for the scrollable region; adds role="region" when set.
## Use when
- Use only when visual expression supports storytelling, brand differentiation, or a clear showcase moment.
- Signaling that a scrollable strip or panel has more content by fading its edges toward the background.
- Fading horizontally, vertically, or on both axes depending on how the content overflows.
## Avoid when
- Do not place heavy effects in task-dense workflows where clarity, speed, and readability matter more.
- The scrollable region already has a clear affordance, such as visible scrollbars or pagination; the fade is an additional cue, not a replacement for one.
## Anti-patterns
- Heavy effects in forms or task-dense workflows
- Motion that interferes with reading or focus
## Rules
- Use the `<brok:scroll-fade>` tag (or `<x-ui.scroll-fade>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/scroll-fade
- Registry JSON (files, props, contract): https://brokui.dev/r/open/scroll-fade.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | string | horizontal | Scroll and fade direction: horizontal (default), vertical, or both. |
| hideScrollbar | bool | true | Hides the native scrollbar while keeping the region scrollable. |
| intensity | int | 1 | Opacity multiplier for the edge fades. |
| label | mixed | null | null | Accessible name for the scrollable region; adds role="region" when set. |
Slots
default—
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- Shows or hides each edge fade based on live scroll position, computed on init, resize, and every scroll event.
- hideScrollbar hides the native scrollbar cross-browser while keeping the region scrollable by wheel, touch, or keyboard.
- Installs a JavaScript behavior module when the registry item includes resources/js/ui files.
- Declares registry capability flags: a11y, interactive, responsive, rtl, darkMode, localized.
Guidance
Support brand expression or a showcase moment.
Use when
- Use only when visual expression supports storytelling, brand differentiation, or a clear showcase moment.
- Signaling that a scrollable strip or panel has more content by fading its edges toward the background.
- Fading horizontally, vertically, or on both axes depending on how the content overflows.
Avoid when
- Do not place heavy effects in task-dense workflows where clarity, speed, and readability matter more.
- The scrollable region already has a clear affordance, such as visible scrollbars or pagination; the fade is an additional cue, not a replacement for one.
Use instead
- Static content-first presentation
Anti-patterns
- Heavy effects in forms or task-dense workflows
- Motion that interferes with reading or focus
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- managed
- Focus
managed
- The scrollable viewport carries tabindex="0" so it is keyboard-focusable, and gets role="region" with the label prop as its aria-label when one is given.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Add a stable wire:key when Livewire can reorder this interactive component.
<div wire:key="scroll-fade-{{ $record->id }}">
<x-ui.scroll-fade axis="horizontal" class="max-w-md">
<div class="flex gap-3 p-1">
@foreach (range(1, 10) as $i)
<div class="flex h-24 w-32 shrink-0 items-center justify-center rounded-lg border border-border bg-card text-lg font-semibold text-card-foreground">
{{ __('Card') }} {{ $i }}
</div>
@endforeach
</div>
</x-ui.scroll-fade>
</div>
Source
The exact, editable files ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props([
'axis' => 'horizontal',
'hideScrollbar' => true,
'intensity' => 1,
// Accessible name for the scrollable region. A scroll container must be
// keyboard-focusable (a11y: scrollable-region-focusable); we add tabindex
// and, when labelled, a region role so it's announced.
'label' => null,
])
@php
$overflow = match ($axis) {
'vertical' => 'overflow-y-auto overflow-x-hidden',
'both' => 'overflow-auto',
default => 'overflow-x-auto overflow-y-hidden',
};
// Cross-browser scrollbar hiding without a plugin.
$hide = $hideScrollbar ? '[scrollbar-width:none] [&::-webkit-scrollbar]:hidden' : '';
$fadeBase = 'pointer-events-none absolute z-10 from-background to-transparent';
@endphp
<div
x-data="uiScrollFade({ axis: @js($axis), intensity: @js((float) $intensity) })"
x-init="update(); $nextTick(() => update())"
@resize.window="update()"
data-slot="scroll-fade"
data-axis="{{ $axis }}"
{{ $attributes->merge(['class' => 'relative']) }}
>
@if ($axis === 'horizontal' || $axis === 'both')
<div x-show="start" class="{{ $fadeBase }} inset-y-0 start-0 w-12 bg-gradient-to-r rtl:bg-gradient-to-l" :style="`opacity:${intensity}`"></div>
<div x-show="end" class="{{ $fadeBase }} inset-y-0 end-0 w-12 bg-gradient-to-l rtl:bg-gradient-to-r" :style="`opacity:${intensity}`"></div>
@endif
@if ($axis === 'vertical' || $axis === 'both')
<div x-show="top" class="{{ $fadeBase }} inset-x-0 top-0 h-12 bg-gradient-to-b" :style="`opacity:${intensity}`"></div>
<div x-show="bottom" class="{{ $fadeBase }} inset-x-0 bottom-0 h-12 bg-gradient-to-t" :style="`opacity:${intensity}`"></div>
@endif
<div
x-ref="viewport"
@scroll="update()"
tabindex="0"
@if ($label) role="region" aria-label="{{ $label }}" @endif
class="{{ $overflow }} {{ $hide }} focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{{ $slot }}
</div>
</div>
/**
* Scroll-fade behavior (spec §19 behavior layer).
*
* Tracks how far the viewport is scrolled on each enabled axis and exposes
* boolean edge flags (start/end/top/bottom). The Blade markup binds fade
* overlays to those flags so an edge gradient only shows when there is more
* content to scroll in that direction.
*
* Self-registers on `alpine:init` so import order does not matter.
*/
document.addEventListener('alpine:init', () => {
window.Alpine.data('uiScrollFade', (config = {}) => ({
axis: config.axis || 'horizontal',
intensity: config.intensity ?? 1,
start: false,
end: false,
top: false,
bottom: false,
get horizontal() {
return this.axis === 'horizontal' || this.axis === 'both';
},
get vertical() {
return this.axis === 'vertical' || this.axis === 'both';
},
update() {
const el = this.$refs.viewport;
if (!el) return;
if (this.horizontal) {
// Math.abs keeps this correct for RTL (negative scrollLeft).
const left = Math.abs(el.scrollLeft);
this.start = left > 1;
this.end = left + el.clientWidth < el.scrollWidth - 1;
}
if (this.vertical) {
this.top = el.scrollTop > 1;
this.bottom = el.scrollTop + el.clientHeight < el.scrollHeight - 1;
}
},
}));
});
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.0.3 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0