Skip to content
Sapphire UIv4.1.0

Mobile Nav

Expose site navigation in a compact mobile menu. Use it when the full link list cannot fit beside the brand at narrow widths.

Examples

Router

JSX usage

Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.

bun add @kongmy-dev/sapphire-ui react react-dom radix-ui
"use client";
import { useState } from "react";
import { Container } from "@kongmy-dev/sapphire-ui/container";
import { MobileNav } from "@kongmy-dev/sapphire-ui/mobile-nav";

function MobileNavRouter() {
  const [pathname, setPathname] = useState('/projects');
  return (
    <>
      <MobileNav
        brandName="Workspace"
        pathname={pathname}
        navItems={[
          { href: '/projects', label: 'Projects' },
          {
            href: '/settings',
            label: 'Settings',
            active: pathname === '/settings',
          },
        ]}
        toggleLabel="Open workspace navigation"
        closeLabel="Close workspace navigation"
        onNavigate={(href, event) => {
          event.preventDefault();
          setPathname(href);
        }}
      />
      <Container padding="lg">
        <output>Current route: {pathname}</output>
      </Container>
    </>
  );
}

export default MobileNavRouter;
HTML markup

Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.

Props

Generated from the current public TypeScript signatures, including composed behaviour props. “—” means no default is declared in the local signature; forwarded behaviour defaults are not inferred.

MobileNav

MobileNav component props
PropTypeRequiredLocal default
brandNamestringYes—
brandSuffixstring | undefinedNo''
versionstring | undefinedNo''
navItemsreadonly MobileNavItem[]Yes—
extraActionsReactNodeNo—
pathnamestring | undefinedNo—
onNavigate((href: string, event: MouseEvent<HTMLAnchorElement>) => void) | undefinedNo—
toggleLabelstring | undefinedNo'Toggle navigation menu'
closeLabelstring | undefinedNo'Close navigation menu'

MobileNavItem

Supporting type used by this API.

MobileNavItem component props
PropTypeRequiredLocal default
hrefstringYes—
labelstringYes—
iconReactElement<unknown, string | import("react").JSXElementConstructor<any>> | undefinedNo—
activeboolean | undefinedNo—

Setup

bun add @kongmy-dev/sapphire-ui react react-dom radix-ui

For an app using package components throughout, load the full stylesheet once. Add this component import where you use it.

import "@kongmy-dev/sapphire-ui/sapphire.css";
import { MobileNav } from "@kongmy-dev/sapphire-ui/mobile-nav";

Mixing package and vendored components? Follow application setup.

Search documentation