Shadix.Components.NavigationMenu (shadix v0.0.1)

Copy Markdown View Source

A site navigation menu with dropdown panels, built on client-side JS commands, Floating UI, and a small LiveView hook.

Each navigation_menu_trigger/1 is a <button> whose phx-click toggles its paired navigation_menu_content/1 dropdown panel. The ShadixNavigationMenu hook (assets/ts/navigation_menu.ts) lives on each content panel: it watches the panel's visibility via a MutationObserver, positions it under the trigger with @floating-ui/dom (computePosition + autoUpdate, bottom-start/flip/ shift), syncs the trigger's aria-expanded and data-state (driving the chevron rotation), opens on trigger hover, and closes on outside pointerdown or Escape.

Trigger and content ids are derived from the required :id so aria-controls, data-trigger, and the JS targets line up stably.

NOTE: This is a focused v1. Compared to the shadcn/Radix original it omits the shared animated viewport, motion direction animations (data-motion), the active-link indicator, and pointer-grace hand-off between adjacent panels. Each trigger simply opens its own panel positioned below it; links navigate. Single open-at-a-time across siblings is also not enforced (panels toggle independently).

Summary

Functions

Returns the Phoenix.LiveView.JS command that closes the panel with id.

Renders the navigation menu root.

The dropdown panel for a trigger. :id is the item id.

A single navigation item; wraps a trigger + content, or a link.

A styled navigation link.

The horizontal list of navigation items.

The clickable trigger for a dropdown panel. :id is the item id.

Returns the Phoenix.LiveView.JS command that shows the panel with id.

Returns the Phoenix.LiveView.JS command that toggles the panel with id.

Functions

hide_content(id)

Returns the Phoenix.LiveView.JS command that closes the panel with id.

Used by the hook's data-on-close (Escape / outside click).

show_content(id)

Returns the Phoenix.LiveView.JS command that shows the panel with id.

Used by the trigger's mouseenter to open the panel on hover.

toggle_content(id)

Returns the Phoenix.LiveView.JS command that toggles the panel with id.

The ShadixNavigationMenu hook reacts to the resulting visibility change to position the panel and wire up outside-click / Escape handling.