Scroll Area
A scroll container with themed scrollbars and shadows on the edges with more content beyond them.
c2-scroll-area is a scroll container that looks the part, like the ScrollArea of Mantine, Chakra and PrimeVue or the side panels of Slack and Linear. It keeps native scrolling (wheel, touch, keys, momentum), themes the scrollbar, and casts a shadow on each edge that has content beyond it.
Import
import '@c2n/components/scroll-area'Usage
Member 1
Member 2
Member 3
Member 4
Member 5
Member 6
Member 7
Member 8
Member 9
Member 10
Member 11
Member 12
Member 13
Member 14
Member 15
Member 16
Member 17
Member 18
Member 19
Member 20
Member 1
Member 2
Member 3
Member 4
Member 5
Member 6
Member 7
Member 8
Member 9
Member 10
Member 11
Member 12
Member 13
Member 14
Member 15
Member 16
Member 17
Member 18
Member 19
Member 20
Member 1
Member 2
Member 3
Member 4
Member 5
Member 6
Member 7
Member 8
Member 9
Member 10
Member 11
Member 12
Member 13
Member 14
Member 15
Member 16
Member 17
Member 18
Member 19
Member 20
Member 1
Member 2
Member 3
Member 4
Member 5
Member 6
Member 7
Member 8
Member 9
Member 10
Member 11
Member 12
Member 13
Member 14
Member 15
Member 16
Member 17
Member 18
Member 19
Member 20
Size
The area grows with its content up to --c2-scroll-area--max-height (or --c2-scroll-area--max-width), then scrolls; inside a box with a fixed height, it fills it. orientation picks the axes that scroll: vertical (the default), horizontal or both.
Scrollbars
The scrollbar stays native, so it keeps the platform’s feel and accessibility, and is themed through CSS: --c2-scroll-area__scrollbar--width (thin by default, auto or none), the thumb and track colours, and the thickness where the browser lets it be set. --c2-scroll-area__thumb__hover--color applies while the pointer is over the area: with a transparent thumb, the bar fades in on hover as on macOS.
Shadows and fade
A shadow shows on each edge that has content beyond it and disappears once that edge is reached. Set --c2-scroll-area__shadow--color: transparent to turn shadows off, and --c2-scroll-area__fade--size above 0 to fade the content into those edges instead.
Scrolling from code
scrollToEdge('top' | 'bottom' | 'start' | 'end') jumps to an edge, scrollTo() works as on any element, and viewport is the element that scrolls, for code that needs the real scroller. scroll-edge fires with { edge } when a scroll reaches an edge (not when content loads, and not at the edges the area starts at): the hook for loading more at the end of a feed or the top of a chat. It does not bubble, so a scroll area nested in another does not trigger the outer one’s listener.
Keyboard
A region that scrolls must be reachable from the keyboard, so the area has a tab stop and a name. With a label it is a region landmark; without one it is a group, so several scroll areas on a page do not make landmarks with the same name. Once focused, the arrow keys, Page Up, Page Down, Home and End scroll it.