Mobile menu

The sidebar on a phone: a bar with a menu button that opens the same navigation as a drawer from the left.

Playground

Open the menu, pick an item, or swipe the drawer away.

<!-- Below md the menu, from md the sidebar. Same nav data in both. -->
<div class="md:hidden">
	<MobileMenu name="Kystdata.io" subtitle="Operations" href="/">
		{#snippet logo()}<Logo class="size-8" />{/snippet}
		{#each nav as group}
			<MobileMenuGroup label={group.label}>
				{#each group.items as item}
					<MobileMenuItem href={item.href} icon={item.icon} label={item.label} active={item === current} />
				{/each}
			</MobileMenuGroup>
		{/each}
		{#snippet footer()}
			<MobileMenuItem icon="right-from-bracket" label="Sign out" onclick={signOut} />
		{/snippet}
	</MobileMenu>
</div>

Behaviour

Swipe to close
Drag the drawer left and it follows the finger. Past a third of its width, or with a flick, it closes; otherwise it springs back. Scrolling up and down is left alone.
Other ways out
Tap the strip of page to its right, the close button, or press Escape. Picking an item closes it too.
Thumb sized
Rows are 44px tall and span the drawer; buttons are 40px. Pressing a row lights it, since touch has no hover.
Holds the page still
The page behind doesn’t scroll while it’s open, and the drawer’s own scroll stops at its ends instead of dragging the page.
Notch and home bar
The bar sits below the notch and the drawer’s footer above the home indicator, using the safe-area insets.
Hands over at md
From md the sidebar is back. A drawer still open when the window grows closes itself.

Rules

  • The menu replaces the sidebar below md, with the same items in the same order. Nothing is phone only, nothing is missing.
  • The bar is the brand: app tile, name, and the area underneath. Where you are inside the area goes in the breadcrumb row below it, as on desktop.
  • Two actions in the bar at most, as icon buttons. Everything else goes in the page or the drawer.
  • What the sidebar footer holds (account, settings, sign out) goes in the drawer footer, where the thumb already is.