Biji UI

Navigation Menu

A horizontal navigation bar where hovering or clicking a trigger reveals a positioned content panel.

Installation

biji-ui = { version = "0.5.0", features = ["navigation_menu"] }

Usage

use leptos::prelude::*;
use biji_ui::components::navigation_menu;

#[component]
pub fn MyNav() -> impl IntoView {
    view! {
        <navigation_menu::Root>
            <navigation_menu::List class="flex items-center gap-1">
                <navigation_menu::Item value="docs">
                    <navigation_menu::Trigger class="px-3 py-1.5 text-sm rounded-md transition hover:bg-accent">
                        "Docs"
                    </navigation_menu::Trigger>
                    <navigation_menu::Content
                        class="z-50 min-w-48 rounded-lg border shadow-md transition bg-background border-border origin-[var(--biji-transform-origin)]"
                        show_class="opacity-100 scale-100 duration-150 ease-out"
                        hide_class="opacity-0 scale-95 duration-100 ease-in"
                    >
                        <div class="grid gap-1 p-2">
                            <navigation_menu::Link
                                href="/docs/getting-started"
                                class="block px-3 py-2 text-sm rounded-md hover:bg-accent"
                            >
                                "Getting Started"
                            </navigation_menu::Link>
                            <navigation_menu::Link
                                href="/docs/accordion"
                                class="block px-3 py-2 text-sm rounded-md hover:bg-accent"
                            >
                                "Accordion"
                            </navigation_menu::Link>
                        </div>
                    </navigation_menu::Content>
                </navigation_menu::Item>
                <navigation_menu::Item value="github">
                    <navigation_menu::Link
                        href="https://github.com/biji-ui/biji-ui"
                        class="block px-3 py-1.5 text-sm rounded-md transition hover:bg-accent"
                    >
                        "GitHub"
                    </navigation_menu::Link>
                </navigation_menu::Item>
            </navigation_menu::List>
        </navigation_menu::Root>
    }
}

API Reference

Root

NameTypeDefaultDescription
classString""CSS class applied to the `<nav>` element.
aria_labelOption<String>NoneValue of the `aria-label` attribute on the `<nav>` element.
positioningPositioningBottomStartWhere to render each Content panel relative to its Trigger.
avoid_collisionsAvoidCollisionsFlipHow content panels react when they would overflow the viewport.
close_delayDuration200msHow long after the pointer leaves a Trigger or Content before the panel closes.
hide_delayDuration200msHow long to wait before unmounting the content after closing begins (should match your CSS transition duration).

List

NameTypeDefaultDescription
classString""CSS class applied to the `<ul>` element.

Item

NameTypeDefaultDescription
valueStringUnique string that identifies this item. Must match the corresponding Content panel.
classString""CSS class applied to the `<li>` element.
disabledboolfalseWhen true, the item's Trigger cannot be interacted with.

Trigger

NameTypeDefaultDescription
classString""CSS class applied to the `<button>` element.

Content

NameTypeDefaultDescription
classString""CSS class applied in both open and closed states.
show_classString""CSS class applied when the panel is open.
hide_classString""CSS class applied while the panel is closing.

Link

NameTypeDefaultDescription
hrefStringThe URL the link navigates to.
classString""CSS class applied to the `<a>` element.
disabledboolfalseWhen true, renders `aria-disabled` and `data-disabled` on the anchor.
close_on_clickbooltrueWhen true, clicking the link closes any open content panel.

Data Attributes

AttributeDescription
data-state"open" when the item's panel is visible; "closed" otherwise. Present on Trigger.
data-disabledPresent on Item, Trigger, and Link when the item is disabled.
data-highlightedPresent on Trigger when it holds roving-tabindex focus.

Keyboard Navigation

KeyDescription
TabMoves focus into and out of the navigation menu. When a panel is open, Tab moves into the panel.
ArrowRightMoves focus to the next Trigger or Link. If a panel is open, opens the next item's panel.
ArrowLeft / ArrowUpMoves focus to the previous Trigger or Link. If a panel is open, opens the previous item's panel.
ArrowDownOpens the current item's Content panel and focuses the first focusable element inside it.
HomeMoves focus to the first Trigger or Link.
EndMoves focus to the last Trigger or Link.
Enter / SpaceToggles the current item's Content panel.
EscapeCloses the open panel and returns focus to its Trigger.