Repository navigation
Example of using ScrollArea within a sheet #8694
Replies: 3 comments
|
Yes, I used it. Shadcn ScrollArea requires a fixed height, so for dynamic layouts, we calculate the height based on available space. |
|
The trick is that the import {
Sheet, SheetContent, SheetHeader, SheetTitle, SheetFooter,
} from '@/components/ui/sheet'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Button } from '@/components/ui/button'
export function ExampleSheet() {
return (
<Sheet>
{/* trigger etc. */}
<SheetContent className="flex flex-col">
<SheetHeader>
<SheetTitle>Title</SheetTitle>
</SheetHeader>
<ScrollArea className="min-h-0 flex-1">
<div className="space-y-4 pr-4">
{/* your long content here */}
</div>
</ScrollArea>
<SheetFooter>
<Button>Save</Button>
</SheetFooter>
</SheetContent>
</Sheet>
)
}The two details that make or break it:
If your And if you don't actually need Radix's custom scrollbar, a plain |
|
The Sheet already clips overflow. ScrollArea only works if it is given a bounded height inside that clip. The usual miss is leaving This pattern works with the current shadcn Sheet + ScrollArea: import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetDescription,
} from '@/components/ui/sheet'
import { ScrollArea } from '@/components/ui/scroll-area'
export function Example({ open, onOpenChange }: { open: boolean; onOpenChange: (v: boolean) => void }) {
return (
<Sheet open={open} onOpenChange={onOpenChange}>
<SheetContent className="flex h-full flex-col gap-0 p-0 sm:max-w-md">
<SheetHeader className="shrink-0 border-b px-6 py-4">
<SheetTitle>Details</SheetTitle>
<SheetDescription>Long list, header stays put.</SheetDescription>
</SheetHeader>
<ScrollArea className="min-h-0 flex-1">
<div className="space-y-4 px-6 py-4">
{Array.from({ length: 40 }, (_, i) => (
<p key={i}>Row {i + 1}</p>
))}
</div>
</ScrollArea>
</SheetContent>
</Sheet>
)
}Why those classes matter:
Side sheets already have a height. For If this gave you a working sheet, please mark it as the accepted answer. |
Uh oh!
There was an error while loading. Please reload this page.
Does anyone have a working example of using the ScrollArea component within a sheet?
All reactions