Components
Scroll Area
A native scroll container with custom scrollbars.
Anatomy#
Import the component and assemble its parts:
import { ScrollArea } from '@egoist/solid-base/scroll-area';
<ScrollArea.Root>
<ScrollArea.Viewport>
<ScrollArea.Content />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar>
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>;Examples#
Both scrollbars#
Use <ScrollArea.Corner> to prevent the scrollbars from intersecting.
Gradient scroll fade#
Use the viewport overflow CSS variables to drive a CSS mask, which gradually increases the fade as the user scrolls away from the edges.
.Viewport {
mask-image: linear-gradient(
to bottom,
transparent 0,
black min(40px, var(--scroll-area-overflow-y-start)),
black calc(100% - min(40px, var(--scroll-area-overflow-y-end, 40px))),
transparent 100%
);
mask-repeat: no-repeat;
}For SSR, a fallback can be used as part of the end-side var() call so the mask is visible
before the overflow CSS variables hydrate.
var(--scroll-area-overflow-y-end, 40px);When the fade is applied to <ScrollArea.Viewport> itself, the variables can be used directly.
However, inheritance to children is disabled, so they must explicitly opt in using the inherit
keyword.
.Child {
--scroll-area-overflow-y-start: inherit;
--scroll-area-overflow-y-end: inherit;
}API reference#
<ScrollArea.Root>
Groups all parts of the scroll area. Renders a <div> element.
overflowEdgeThresholdnumber | Partial<OverflowEdges<number>>0The threshold in pixels that must be passed before the overflow edge attributes are applied. Accepts a single number for all edges or an object to configure them individually.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-scrollingPresent when the user scrolls inside the scroll area.
data-has-overflow-xPresent when the scroll area content is wider than the viewport.
data-has-overflow-yPresent when the scroll area content is taller than the viewport.
data-overflow-x-startPresent when there is overflow on the horizontal start side.
data-overflow-x-endPresent when there is overflow on the horizontal end side.
data-overflow-y-startPresent when there is overflow on the vertical start side.
data-overflow-y-endPresent when there is overflow on the vertical end side.
--scroll-area-corner-heightThe scroll area's corner height.
--scroll-area-corner-widthThe scroll area's corner width.
<ScrollArea.Viewport>
The actual scrollable container of the scroll area. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-scrollingPresent when the user scrolls inside the scroll area.
data-has-overflow-xPresent when the scroll area content is wider than the viewport.
data-has-overflow-yPresent when the scroll area content is taller than the viewport.
data-overflow-x-startPresent when there is overflow on the horizontal start side.
data-overflow-x-endPresent when there is overflow on the horizontal end side.
data-overflow-y-startPresent when there is overflow on the vertical start side.
data-overflow-y-endPresent when there is overflow on the vertical end side.
--scroll-area-overflow-x-startThe distance from the horizontal start edge in pixels.
--scroll-area-overflow-x-endThe distance from the horizontal end edge in pixels.
--scroll-area-overflow-y-startThe distance from the vertical start edge in pixels.
--scroll-area-overflow-y-endThe distance from the vertical end edge in pixels.
<ScrollArea.Scrollbar>
A vertical or horizontal scrollbar for the scroll area. Renders a <div> element.
orientation'vertical' | 'horizontal''vertical'Whether the scrollbar controls vertical or horizontal scroll.
keepMountedbooleanfalseWhether to keep the HTML element in the DOM when the viewport isn't scrollable.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-orientationIndicates the orientation of the scrollbar.
data-hoveringPresent when the pointer is over the scroll area.
data-scrollingPresent when the user scrolls inside the scroll area.
data-has-overflow-xPresent when the scroll area content is wider than the viewport.
data-has-overflow-yPresent when the scroll area content is taller than the viewport.
data-overflow-x-startPresent when there is overflow on the horizontal start side.
data-overflow-x-endPresent when there is overflow on the horizontal end side.
data-overflow-y-startPresent when there is overflow on the vertical start side.
data-overflow-y-endPresent when there is overflow on the vertical end side.
--scroll-area-thumb-heightThe scroll area thumb's height.
--scroll-area-thumb-widthThe scroll area thumb's width.
<ScrollArea.Content>
A container for the content of the scroll area. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-scrollingPresent when the user scrolls inside the scroll area.
data-has-overflow-xPresent when the scroll area content is wider than the viewport.
data-has-overflow-yPresent when the scroll area content is taller than the viewport.
data-overflow-x-startPresent when there is overflow on the horizontal start side.
data-overflow-x-endPresent when there is overflow on the horizontal end side.
data-overflow-y-startPresent when there is overflow on the vertical start side.
data-overflow-y-endPresent when there is overflow on the vertical end side.
<ScrollArea.Thumb>
The draggable part of the scrollbar that indicates the current scroll position. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-orientationIndicates the orientation of the scrollbar.
data-scrollingPresent when the user scrolls inside the scroll area.
<ScrollArea.Corner>
A small rectangular area that appears at the intersection of horizontal and vertical scrollbars. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.