Shadwire

Search the documentation

Search the documentation and component pages by title and by content.

Get started
Introduction
Installation
shadwire.json
Theming
Dark mode
Tools
CLI
Agent skill
Registry
llms.txt
Guides
Composition
Styling
Forms
Icons
Accessibility
Localisation
Blocks
Overview
Components
Overview
Accordion
Alert
Alert Dialog
Aspect Ratio
Avatar
Badge
Breadcrumb
Button
Button Group
Calendar
Card
Carousel
Chart
Checkbox
Collapsible
Combobox
Command
Context Menu
Data Table
Date Picker
Dialog
Drawer
Dropdown Menu
Empty
Field
Hover Card
Icon
Input
Input Group
Input OTP
Item
Kbd
Label
Menubar
Native Select
Navigation Menu
Pagination
Popover
Progress
Radio Group
Resizable
Scroll Area
Select
Separator
Sheet
Sidebar
Skeleton
Slider
Sonner
Spinner
Switch
Table
Tabs
Textarea
Toggle
Toggle Group
Tooltip

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:

shadwire add scroll-area --yes

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.

<%= ui_scroll_area(class: "h-[200px] w-[350px] rounded-md border p-4") do %>
  Your scrollable content here.
<% end %>
<%= render Ui::ScrollAreaComponent.new(class: "h-[200px] w-[350px] rounded-md border p-4") do %>
  Your scrollable content here.
<% end %>

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.

ScrollArea
`-- ScrollBar

Examples

Preview

A vertical scroll area: native scrolling, with a scrollbar that matches the theme.

Release note 1: Rails components are copied into the app and can be edited in place after installation.

Release note 2: Rails components are copied into the app and can be edited in place after installation.

Release note 3: Rails components are copied into the app and can be edited in place after installation.

Release note 4: Rails components are copied into the app and can be edited in place after installation.

Release note 5: Rails components are copied into the app and can be edited in place after installation.

Release note 6: Rails components are copied into the app and can be edited in place after installation.

Release note 7: Rails components are copied into the app and can be edited in place after installation.

Release note 8: Rails components are copied into the app and can be edited in place after installation.

Release note 9: Rails components are copied into the app and can be edited in place after installation.

Release note 10: Rails components are copied into the app and can be edited in place after installation.

Release note 11: Rails components are copied into the app and can be edited in place after installation.

Release note 12: Rails components are copied into the app and can be edited in place after installation.

<%= ui_scroll_area(class: "h-[200px] w-[350px] rounded-md border p-4", data: { testid: "scroll-area-vertical" }) do %>
  <div class="flex flex-col gap-4 text-sm leading-6">
    <% 12.times do |index| %>
      <p>
        Release note <%= index + 1 %>: Rails components are copied into the app and can be edited in place after installation.
      </p>
    <% end %>
  </div>

Horizontal

Use ui_scroll_bar(orientation: :horizontal) or pass scrollbars: [ :horizontal ] for horizontal scrolling.

Horizontal

Use a horizontal scrollbar for galleries and wide content.

Photo by Ornella Binni
Photo by Ornella Binni
Photo by Tom Byrom
Photo by Tom Byrom
Photo by Vladimir Malyavko
Photo by Vladimir Malyavko
<% works = [
  {
    artist: "Ornella Binni",
    art: "https://images.unsplash.com/photo-1465869185982-5a1a7522cbcb?auto=format&fit=crop&w=300&q=80"
  },
  {
    artist: "Tom Byrom",
    art: "https://images.unsplash.com/photo-1548516173-3cabfa4607e9?auto=format&fit=crop&w=300&q=80"
<%= ui_scroll_area(scrollbars: [ :horizontal ], class: "w-96 rounded-md border whitespace-nowrap") do %>
  <div class="flex w-max gap-4 p-4">...</div>
<% end %>

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.

هذا مثال على محتوى طويل داخل منطقة تمرير باتجاه من اليمين إلى اليسار.

يمكنك تمرير المحتوى مع الحفاظ على اتجاه النص العربي داخل المكون.

تنتقل خصائص HTML مثل dir وdata وaria مباشرة إلى الجذر.

تظل أشرطة التمرير المخصصة متوافقة مع السلوك الأصلي للمتصفح.

هذا السطر الإضافي يجعل المثال قابلاً للتمرير عمودياً.

<%= ui_scroll_area(dir: "rtl", class: "h-[200px] w-[350px] rounded-md border p-4", data: { testid: "scroll-area-rtl" }) do %>
  <div class="flex flex-col gap-4 text-sm leading-6">
    <% [
      "هذا مثال على محتوى طويل داخل منطقة تمرير باتجاه من اليمين إلى اليسار.",
      "يمكنك تمرير المحتوى مع الحفاظ على اتجاه النص العربي داخل المكون.",
      "تنتقل خصائص HTML مثل dir وdata وaria مباشرة إلى الجذر.",
      "تظل أشرطة التمرير المخصصة متوافقة مع السلوك الأصلي للمتصفح.",
      "هذا السطر الإضافي يجعل المثال قابلاً للتمرير عمودياً."

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.