Sidebar is a vertical navigation component that provides a structured layout with optional header and footer sections. It's commonly used within the Scaffold component for application navigation.
Main content area
Prop | Type | Default |
|---|---|---|
No dataThere are no records to display | ||
When used within the Scaffold component's start or end snippets, the Sidebar automatically
receives fixed positioning.
You must specify the Sidebar width using the class prop and apply corresponding margins to the main content:
w-48, use ml-48 or mr-48 in Scaffold's mainClassw-64, use ml-64 or mr-64 in Scaffold's mainClassWhen using Sidebar with an AppBar, apply vh-* utilities to ensure proper height calculation:
vh-16 when AppBar has h-16vh-32 when both AppBar and BottomBar
have h-16mt-16 to match the AppBar height<Scaffold
mainClass="lg:ml-48 vh-16 mt-16"
startClass="vh-16 mt-16"
>
{#snippet appBar()}
<AppBar class="h-16">
<!-- AppBar content -->
</AppBar>
{/snippet}
{#snippet start()}
<Sidebar class="w-48">
{#snippet header()}
<h3>Navigation</h3>
{/snippet}
<SideNav items={navItems} />
{#snippet footer()}
<Button variant="ghost">Sign Out</Button>
{/snippet}
</Sidebar>
{/snippet}
<!-- Main content -->
<div class="p-4">
<h1>Main Content</h1>
</div>
</Scaffold>In this example:
vh-16 calculates height as calc(100vh - 4rem)mt-16 creates space for the fixed
AppBarml-48 creates space for the fixed
Sidebar💡 Tip: The Sidebar component is designed to work seamlessly with the Scaffold component. For
responsive layouts, consider using Tailwind's responsive prefixes (e.g., lg:ml-48) to show/hide the
Sidebar on different screen sizes.
<Scaffold
mainClass="lg:ml-48 vh-16 mt-16"
startClass="invisible lg:visible vh-16 mt-16"
>
{#snippet appBar()}
<AppBar class="h-16">
{#snippet start()}
<IconButton
icon="fluent:navigation-24-regular"
onclick={() => drawerOpen = true}
class="lg:hidden"
/>
{/snippet}
</AppBar>
{/snippet}
{#snippet start()}
<Sidebar class="w-48">
<SideNav items={navItems} />
</Sidebar>
{/snippet}
<div class="p-4">Main content</div>
</Scaffold>
<!-- Mobile drawer -->
<Drawer bind:open={drawerOpen}>
<Sidebar class="w-64">
<SideNav items={navItems} />
</Sidebar>
</Drawer>This pattern shows the Sidebar on desktop screens (lg and above) and uses a Drawer for mobile devices.