Layout
Scroll Area A custom scrollable container with styled scrollbars that integrates with the design system.
npm pnpm yarn bun
npm install @morphos/layout
import { ScrollArea, ScrollAreaViewport, ScrollAreaScrollbar, ScrollAreaThumb } from '@morphos/layout'
@ Component ()
class MyComponent extends StatefulComponent {
@ State () scrollArea = new ScrollArea ({ type: 'hover' })
render () {
return (
< ScrollArea scrollArea = { this .scrollArea}>
< ScrollAreaViewport scrollArea = { this .scrollArea}>
< p >Long content that overflows the container...</ p >
{ /* more content */ }
</ ScrollAreaViewport >
< ScrollAreaScrollbar scrollArea = { this .scrollArea} orientation = "vertical" >
< ScrollAreaThumb scrollArea = { this .scrollArea} orientation = "vertical" />
</ ScrollAreaScrollbar >
</ ScrollArea >
)
}
}
Scrolling happens natively on ScrollAreaViewport — the native scrollbar is hidden with CSS, and ScrollAreaScrollbar/ScrollAreaThumb render a decorative, ARIA-described overlay driven by the real scroll metrics.
Component Description ScrollAreaRoot container — tracks scroll metrics and whether the content overflows ScrollAreaViewportThe actual scrollable element (overflow: auto) — reports scroll metrics to ScrollArea ScrollAreaScrollbarThe scrollbar track (role="scrollbar") ScrollAreaThumbThe draggable-looking thumb, sized/positioned from real scroll metrics via CSS custom properties
Prop Type Default Description type"auto" | "always" | "scroll" | "hover" | "hidden""hover"When scrollbars are visible. This is exposed as data-type for CSS to act on — "hidden" is expected to hide the custom scrollbar entirely via CSS while the viewport still scrolls natively. classstring— CSS class idstring— HTML id
Method Description _onScroll(el: HTMLElement)Internal — called by ScrollAreaViewport on mount and on every scroll event to update tracked metrics
Prop Type Default Description scrollAreaScrollArea— The ScrollArea state instance childrenChildren— The scrollable content classstring— CSS class idstring— HTML id
Prop Type Default Description scrollAreaScrollArea— The ScrollArea state instance orientation"vertical" | "horizontal""vertical"Scrollbar axis childrenChildren— Typically a ScrollAreaThumb classstring— CSS class idstring— HTML id
Prop Type Default Description scrollAreaScrollArea— The ScrollArea state instance — used to size/position the thumb proportionally to the visible fraction of content orientation"vertical" | "horizontal""vertical"Which scroll axis to size/position against classstring— CSS class idstring— HTML id
Attribute Element When present data-typeScrollArea Always — reflects the type prop value data-scrollableScrollArea Content overflows the viewport on either axis data-orientationScrollAreaScrollbar Always — reflects the orientation prop
ScrollAreaThumb doesn't read data-* attributes for sizing — it sets the CSS custom properties --morphos-thumb-size and --morphos-thumb-offset directly on its own inline style, computed from the tracked scroll metrics.
.morphos-scroll-area-viewport {
scrollbar-width : none ;
}
.morphos-scroll-area [ data-type = "hover" ] .morphos-scroll-area-scrollbar {
opacity : 0 ;
transition : opacity var ( --morphos-transition-medium );
}
.morphos-scroll-area [ data-type = "hover" ] :hover .morphos-scroll-area-scrollbar {
opacity : 1 ;
}
.morphos-scroll-area-scrollbar [ data-orientation = "vertical" ] .morphos-scroll-area-thumb {
top : var ( --morphos-thumb-offset , 0 % );
height : var ( --morphos-thumb-size , 100 % );
}