Scroll Area
A scrollable viewport with custom, styleable scrollbars.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase scroll-area
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase scroll-area
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::scroll_area::{
ScrollAreaContent,
ScrollAreaCorner,
ScrollAreaRoot,
ScrollAreaScrollbar,
ScrollAreaThumb,
ScrollAreaViewport,
};
ScrollAreaRoot::new()
.child(
ScrollAreaCorner::new(),
)
.child(
ScrollAreaScrollbar::new()
.child(
ScrollAreaThumb::new(),
),
)
.child(
ScrollAreaViewport::new()
.child(
ScrollAreaContent::new(),
),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#ScrollAreaRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::scroll_area::ScrollAreaRoot;
ScrollAreaRoot::new()
.id("example-id")
.overflow_edge_threshold(/* threshold: impl Into<ScrollAreaEdgeThreshold> */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaRoot with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<ScrollAreaChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<ScrollAreaChild>>,) -> Self
Adds multiple typed children in iteration order. |
.overflow_edge_threshold | pub fn overflow_edge_threshold(mut self, threshold: impl Into<ScrollAreaEdgeThreshold>,) -> Self
Distance thresholds gating the overflow-edge flags; accepts a uniform [ |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ScrollAreaRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ScrollAreaContent
Contains the component's user-provided content.
use base_gpui::scroll_area::ScrollAreaContent;
ScrollAreaContent::new()
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaContent with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl IntoElement) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self
Adds multiple typed children in iteration order. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ScrollAreaContent also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ScrollAreaCorner
Public renderable part of the Scroll Area Corner component.
use base_gpui::scroll_area::ScrollAreaCorner;
ScrollAreaCorner::new()
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaCorner with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaCornerStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ScrollAreaCorner also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ScrollAreaScrollbar
Public renderable part of the Scroll Area Scrollbar component.
use base_gpui::scroll_area::ScrollAreaScrollbar;
ScrollAreaScrollbar::new()
.id("example-id")
.orientation(/* orientation: ScrollAreaOrientation */)
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaScrollbar with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.orientation | pub fn orientation(mut self, orientation: ScrollAreaOrientation) -> Self
Which axis this scrollbar tracks; defaults to vertical. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keep the scrollbar in the tree while its axis has no overflow; defaults to false. |
.child | pub fn child(mut self, child: impl Into<ScrollAreaScrollbarChild>) -> Self
Adds one typed child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaScrollbarStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ScrollAreaScrollbar also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ScrollAreaThumb
Interactive or visual handle representing the current value.
use base_gpui::scroll_area::ScrollAreaThumb;
ScrollAreaThumb::new()
.style_with_state(|/* callback arguments */| { /* handle change */ })
.take_style();
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaThumb with its default configuration. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaThumbStyleState, ScrollbarStyle) -> ScrollbarStyle + 'static,) -> Self
Adjust the primitive's thumb/track appearance from the thumb's Scroll Area facts. Receives [ |
.take_style | pub fn take_style(self) -> Option<Rc<ThumbStyleFn>>The configured style callback, consumed by the Scrollbar part when it builds the primitive. ScrollAreaThumb also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ScrollAreaViewport
Defines the viewport used to lay out or constrain overlay content.
use base_gpui::scroll_area::ScrollAreaViewport;
ScrollAreaViewport::new()
.id("example-id")
.aria_label("label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ScrollAreaViewport with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<ScrollAreaViewportChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<ScrollAreaViewportChild>>,) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Wrap an arbitrary element as viewport content (Content is optional for vertical-only use). |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible name for the scroll region, exposed via |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ScrollAreaRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ScrollAreaViewport also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.