Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Scroll Area examples · Advanced

Both Orientations Scroll Area for React

A scroll area that scrolls both ways, for a table with more columns and rows than fit.

Framework
UI library

Wide tables with many columns make people pan sideways, lose context, then scroll down and lose their place again. This example puts a six-column, twenty-row table in a 400px Scroll Area that scrolls on both axes. The inner wrapper uses w-max, so the columns never wrap and the content sets the width. Use it for data tables, spreadsheets, and admin panels whose content is both wider and taller than its frame.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

Why does this table scroll both ways?

ScrollArea is h-[400px] and max-w-md, and the table sits in a div with w-max. The fixed height scrolls the twenty rows. w-max lets the six columns run wider than the frame.

Which bar does this file add?

ScrollBar with orientation set to horizontal. The root already renders the vertical bar. Both are inside the same ScrollArea.

What are the columns?

Name, Email, Role, Department, Location, and Status. Each th and the cells use px-4 py-2 and text-start. Body cells that are secondary, such as the email, add text-sm text-muted-foreground.

How many people are in the table?

Twenty, from Array.from. Role cycles Admin, Editor, and Viewer. Department cycles Engineering, Design, Marketing, and Sales. Location is San Francisco or New York. Status is Active or Inactive.

Where is the padding around the table?

p-4 is on the w-max wrapper, so it scrolls with the table. The frame is rounded-md border bg-background on ScrollArea, plus w-full max-w-md.

Do the column headings stick?

No. The thead is ordinary table markup inside the scrolling wrapper, so the headings move with the rows. border-b on the header row and on each body row draws the lines.