Scroll Area
Improves native scrolling with a styled scrollbar that looks the same across browsers.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The scroll-area registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/scroll_area_component.rb -
app/components/ui/scroll_area/viewport_component.rb -
app/components/ui/scroll_area/content_component.rb -
app/components/ui/scroll_area/scrollbar_component.rb -
app/components/ui/scroll_area/thumb_component.rb -
app/components/ui/scroll_area/corner_component.rb -
app/helpers/ui/scroll_area_helper.rb -
app/javascript/controllers/ui_scroll_area_controller.js -
vendor/shadwire/shadwire.css
This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
Use the helper in views, or render the ViewComponent class directly when you need the component object.
Composition
shadcn's anatomy is ScrollArea
with an optional ScrollBar.
In Shadwire, ui_scroll_area
renders the viewport, the content, the bars, the thumb and the corner for you.
Examples
Preview
A vertical scroll area: native scrolling, with a scrollbar that matches the theme.
Horizontal
Use ui_scroll_bar(orientation: :horizontal)
or pass scrollbars: [ :horizontal ]
for horizontal scrolling.
Horizontal
Use a horizontal scrollbar for galleries and wide content.
RTL
Pass the standard HTML direction attributes through the component when rendering right-to-left content.
RTL
Use dir: "rtl" when rendering right-to-left content.
API reference
This Rails port mirrors those Base UI-style parts with ViewComponent
classes and data attributes. The helpers preserve free-form HTML
attributes, including data: and
aria:.
| Helper | Main arguments | Description |
|---|---|---|
ui_scroll_area |
scrollbars, class / class_name |
The root component: renders the viewport, content, bars, corner and the Stimulus controller. |
ui_scroll_bar |
orientation |
An optional subcomponent for a vertical or horizontal bar. |
Ui::ScrollAreaComponent |
scrollbars, HTML attributes |
The ViewComponent API for rendering the Rails port directly. |