Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Bottom Navigation for Vue UI SDK

A mobile tab bar for Vue and UI SDK that keeps three to five sections at the bottom of the screen, with badges and room for the home indicator.

On this page9 sections

Bottom navigation keeps the three to five main sections of a phone app in a bar along the bottom of the screen, where a thumb reaches them, and lights up the one you're in. Each item is an icon over a short label, and the bar pads itself clear of the iPhone home indicator.

On a wide screen the same destinations belong in a Sidebar. To switch between views inside one screen, such as posts and replies on a profile, use Tabs.

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.

Anatomy

Bottom Navigation anatomy: root, content, list, item, item icon, item label

Usage

<script setup lang="ts">
import { HomeIcon, SearchIcon, UserIcon } from "lucide-vue-next";
import {
  BottomNavigation, BottomNavigationContent, BottomNavigationItem,
  BottomNavigationItemIcon, BottomNavigationItemLabel,
  BottomNavigationList,
} from "@/components/ui/bottom-navigation";
</script>

Each BottomNavigationItem opens the BottomNavigationContent with the same value. The list is fixed to the bottom of the viewport, so the page needs room underneath for it.

<template>
  <BottomNavigation defaultValue="home">
    <BottomNavigationContent value="home">Your feed</BottomNavigationContent>
    <BottomNavigationContent value="search">Search</BottomNavigationContent>
    <BottomNavigationContent value="profile">Your profile</BottomNavigationContent>
    <BottomNavigationList>
      <BottomNavigationItem value="home">
        <BottomNavigationItemIcon>
          <HomeIcon />
        </BottomNavigationItemIcon>
        <BottomNavigationItemLabel>Home</BottomNavigationItemLabel>
      </BottomNavigationItem>
      <BottomNavigationItem value="search">
        <BottomNavigationItemIcon>
          <SearchIcon />
        </BottomNavigationItemIcon>
        <BottomNavigationItemLabel>Search</BottomNavigationItemLabel>
      </BottomNavigationItem>
      <BottomNavigationItem value="profile">
        <BottomNavigationItemIcon>
          <UserIcon />
        </BottomNavigationItemIcon>
        <BottomNavigationItemLabel>Profile</BottomNavigationItemLabel>
      </BottomNavigationItem>
    </BottomNavigationList>
  </BottomNavigation>
</template>

Accessibility

BottomNavigationList is a tab list named Main, and its aria-label takes another name. Each item is a tab that reports aria-selected, and the open section is a tab panel labeled by its item. Only the selected item is in the tab order, or the first enabled one while no section is selected. The arrow keys move along the bar and open each section they land on. A disabled item still takes focus, so people can find it, but it never opens. The icon is hidden from screen readers, so every item needs a visible label or an aria-label.

Tab
From outside the bar, moves focus to the selected item, or to the first enabled one when no section is selected. From an item, moves focus out of the bar to the next focusable element.
Arrow Down
Moves focus to the next item in vertical orientation and opens its section, unless the item is disabled.
Arrow Right
Moves focus to the next item in horizontal orientation and opens its section, unless the item is disabled. In a right-to-left layout it moves to the previous item.
Arrow Up
Moves focus to the previous item in vertical orientation and opens its section, unless the item is disabled.
Arrow Left
Moves focus to the previous item in horizontal orientation and opens its section, unless the item is disabled. In a right-to-left layout it moves to the next item.
Home
Moves focus to the first item and opens its section, unless the item is disabled.
End
Moves focus to the last item and opens its section, unless the item is disabled.
Enter
Opens the focused item's section, and follows the link when the item is one. This is how an item gets selected when activationMode is manual.
Space
Opens the focused item's section, and follows the link when the item is one. This is how an item gets selected when activationMode is manual.

Demos

Controlled

The open section lives in the demo's own state. It goes in as value, comes back through @value-change, and the line above the frame prints it, starting at home. Control the bar when something besides a tap picks the section, such as the current route or a back button. If only taps change it, defaultValue is less code.

Preview width

Disabled

Profile has disabled on its BottomNavigationItem, so it fades and ignores taps, while Home, Search and News switch as usual. The arrow keys still stop on it, but it never opens. Disable an item when its section exists but can't open yet, such as a profile before sign-in, so the other icons keep their places.

Preview width

Icon only

The same four sections with no visible labels, each BottomNavigationItem named by an aria-label that matches its section. With no label beside it, each icon draws at 20 pixels instead of 16. Keep this for icons nobody has to guess, like home and search, because sighted people get no words to go on.

Preview width

Root provider

useBottomNavigation creates the bar's state outside it and BottomNavigationRootProvider takes it as value. The Go to Profile button above the frame calls setValue to switch sections, and the readout beside it follows. Use this when a control outside the bar, like a header button or a notification, has to move it.

Preview width

With badge

News carries a red count of 3 on the corner of its bell: a small destructive Badge positioned inside BottomNavigationItemIcon. Keep a badge for the one section with unread work. The icon wrapper is hidden from screen readers, so the item's aria-label, News, 3 unread, carries the count for them instead.

Preview width

Each item renders a plain <a> through its #render slot, so a tap changes the URL hash as well as the section. With activationMode set to manual, the arrow keys only move focus and Enter follows the focused link. The selection starts from defaultValue and never reads the URL, so in an app set value from the current path.

Preview width

FAQ

When should I use Bottom Navigation instead of a sidebar or tabs?

Use Bottom Navigation for the three to five top-level sections of a phone layout, the places someone goes back to all day, such as Home, Search, Inbox and Profile. Every item takes an equal share of the width and a long label is cut off with an ellipsis, so a sixth item rarely fits on a phone.

On a wider screen, move the same destinations into a Sidebar and render the bar only below that breakpoint. To switch views within one screen, use Tabs, which sit at the top of the content they change.

How do I control the active Bottom Navigation item from state?

Bind a ref to BottomNavigation with v-model, or pass :value and listen to @value-change as the Controlled demo does. The event's payload is an object with the new section in value.

To move the bar from code outside it without holding the state yourself, create the state with useBottomNavigation, hand it to BottomNavigationRootProvider and call setValue, as in Root provider. For only a starting section, defaultValue is enough.

Why is the bottom of my page hidden behind Bottom Navigation?

BottomNavigationList is fixed to the bottom of the viewport above the page, so the last 3.5rem of content scrolls underneath it. The bar is translucent and blurs what passes behind it, which makes the overlap easy to miss.

Give the scrolling content bottom padding as tall as the bar plus the safe-area inset, such as pb-[calc(3.5rem+env(safe-area-inset-bottom))]. To keep the bar inside a frame or a phone mockup instead, add the static class to BottomNavigationList, which is how every demo on this page renders it.

Does Bottom Navigation handle the iPhone home indicator?

It does, once the page opts in. BottomNavigationList pads its bottom edge by env(safe-area-inset-bottom), and BottomNavigation reserves the bar's 3.5rem plus that inset as its minimum height, so the labels sit above the home indicator.

iOS reports the inset only to a page whose viewport meta tag includes viewport-fit=cover. Without it the inset is zero and the padding does nothing.

Why does a Bottom Navigation section reset when I switch back to it?

Because it left the DOM. BottomNavigation turns on lazyMount and unmountOnExit, so a section mounts when it is first opened and unmounts when another one opens, taking a scrolled list, a half-typed search and every component's state with it.

Set unmountOnExit to false on BottomNavigation to keep every section mounted from the start, hidden until it opens. When the items are routes, the router decides what survives, so keep shared state above the routes or in the URL.

How do I show a notification badge on a Bottom Navigation item?

Put a Badge inside BottomNavigationItemIcon, give that wrapper the relative class and position the badge absolutely at its top corner, as the With badge demo does with a count of 3 on News.

The icon wrapper is hidden from screen readers, so nobody using one hears the badge itself. Put the count in the item's name as well, with an aria-label on BottomNavigationItem such as the demo's News, 3 unread, and update it when the count changes.

Is an icon-only Bottom Navigation accessible?

It is once every item has a name. The icon wrapper is hidden from screen readers, so an item with no label is announced as a tab with no name at all. Give each BottomNavigationItem an aria-label with its section, as the Icon only demo does.

The list is named Main, and an aria-label on BottomNavigationList changes that. Sighted people still get only the pictures, so keep icon-only bars to icons nobody has to guess.

API Reference

BottomNavigation

PropType
value?string | null

The selected item. Pass it to control the navigation. Two-way with v-model.

Type
string | null
defaultValue?string | null

The item selected at first, when uncontrolled.

Type
string | null
Default
null
activationMode?"automatic" | "manual"

automatic selects an item as soon as the arrow keys focus it, manual waits for Enter or Space.

Type
"automatic" | "manual"
Default
"automatic"
debug?boolean

Logs every state change with its reason to the console, in development builds.

hiddenUntilFound?boolean

Keeps hidden panels in the page as hidden="until-found", so the browser's find in page can match their text and select their tab. Implies keepMounted.

Default
false
lazyMount?boolean

With unmountOnExit, only the selected item's panel is mounted. Turn either off to keep every panel mounted, hidden.

Default
true
loopFocus?boolean

Whether the arrow keys wrap from the last item to the first.

Default
true
orientation?"horizontal" | "vertical"

Which arrow keys move between items.

Type
"horizontal" | "vertical"
unmountOnExit?boolean

Unmount a panel when another item is selected. Turn it off (or lazyMount) to keep every panel mounted, hidden.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@value-change(details: BottomNavigationValueChangeDetails) → void

Runs when the selected item changes.

Type
(details: BottomNavigationValueChangeDetails) → void
Parameters

details – { value: string }

Returns
void

BottomNavigationRootProvider

<div> data-slot="tabs"

PropType
valueobject

The API from useBottomNavigation.

Type
{ focus: () → void; setValue: (value: string) → void; value: string | null }
debug?boolean

Logs every state change with its reason to the console, in development builds.

hiddenUntilFound?boolean

Keeps hidden panels in the page as hidden="until-found", so the browser's find in page can match their text and select their tab. Implies keepMounted.

Default
false
lazyMount?boolean

With unmountOnExit, only the selected item's panel is mounted. Turn either off to keep every panel mounted, hidden.

Default
true
unmountOnExit?boolean

Unmount a panel when another item is selected. Turn it off (or lazyMount) to keep every panel mounted, hidden.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-activation-direction"none" | "left" | "right" | "up" | "down"

Which way the last selection moved on screen. Use it to slide panels in from the right side.

Type
"none" | "left" | "right" | "up" | "down"
data-orientation"horizontal" | "vertical"

Which arrow keys move between tabs.

Type
"horizontal" | "vertical"

BottomNavigationList

<div> data-slot="tabs-list"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-activation-direction"none" | "left" | "right" | "up" | "down"

Which way the last selection moved on screen. Use it to slide panels in from the right side.

Type
"none" | "left" | "right" | "up" | "down"
data-has-icons?string

Present while any tab inside holds an icon part, so items without one can line up.

data-orientation"horizontal" | "vertical"

Which arrow keys move between tabs.

Type
"horizontal" | "vertical"

BottomNavigationItem

<button> data-slot="tabs-tab"

PropType
valuestring

Identifies the tab and pairs it with the panel of the same value.

disabled?boolean

Keeps the tab focusable but stops it from being selected, as the tabs pattern asks.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-activation-direction"none" | "left" | "right" | "up" | "down"

Which way the last selection moved on screen. Use it to slide panels in from the right side.

Type
"none" | "left" | "right" | "up" | "down"
data-disabled?string

Present when the tab can't be selected.

data-has-icon?string

Present on a tab while it holds an icon part.

data-orientation"horizontal" | "vertical"

Which arrow keys move between tabs.

Type
"horizontal" | "vertical"
data-selected?string

Present on the selected tab and its panel.

BottomNavigationItemIcon

<span> data-slot="tabs-tab-icon"

PropType
mirror?boolean

Flips the icon horizontally in right-to-left text, for icons that point a way, like arrows and chevrons. Icons that picture a thing, like a clock or a check, stay as they are.

Default
false
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-mirror?string

Present on an icon that flips in right-to-left text, with mirror.

BottomNavigationItemLabel

<span> data-slot="bottom-navigation-item-label"

PropType
class?string

Merged with the part's classes.

BottomNavigationContent

<div> data-slot="tabs-panel"

PropType
valuestring

The value of the tab this panel belongs to.

hiddenUntilFound?boolean

Whether the panel stays findable with hidden="until-found" while its tab isn't selected. Overrides the tabs'.

keepMounted?boolean

Whether the panel stays in the page, hidden, while its tab isn't selected. UI SDK's default: false.

Default
keep
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-activation-direction"none" | "left" | "right" | "up" | "down"

Which way the last selection moved on screen. Use it to slide panels in from the right side.

Type
"none" | "left" | "right" | "up" | "down"
data-ending-style?string

Present while the previous panel animates out. Style the state you animate to.

data-orientation"horizontal" | "vertical"

Which arrow keys move between tabs.

Type
"horizontal" | "vertical"
data-selected?string

Present on the selected tab and its panel.

data-starting-style?string

Present for a panel's first frame. Style the state you animate from.

useBottomNavigation

PropType
value?string | null

The selected item. Pass it to control the navigation. Two-way with v-model.

Type
string | null
defaultValue?string | null

The item selected at first, when uncontrolled.

Type
string | null
activationMode?"automatic" | "manual"

automatic selects an item as soon as the arrow keys focus it, manual waits for Enter or Space.

Type
"automatic" | "manual"
Default
"automatic"
loopFocus?boolean

Whether the arrow keys wrap from the last item to the first.

Default
true
orientation?"horizontal" | "vertical"

Which arrow keys move between items.

Type
"horizontal" | "vertical"
EventType
@value-change(details: BottomNavigationValueChangeDetails) → void

Runs when the selected item changes.

Type
(details: BottomNavigationValueChangeDetails) → void
Parameters

details – { value: string }

Returns
void

BottomNavigationContext