Shadix.Components.DropdownMenu (shadix v0.0.1)

Copy Markdown View Source

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

Like the dialog, this is a portal-free, fully client-driven menu. The trigger toggles the menu content with toggle_menu/1 (a Phoenix.LiveView.JS builder with enter/leave transitions); the ShadixDropdownMenu hook (assets/ts/dropdown_menu.ts) watches the content's visibility via a MutationObserver, positions it under the trigger with @floating-ui/dom (computePosition + autoUpdate, bottom-start/flip/shift), manages keyboard navigation (arrows/Home/End/Enter/Escape/Tab), and closes on outside pointerdown via the data-on-close JS (hide_menu/1).

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

Summary

Functions

Renders a dropdown menu with a :trigger slot and arbitrary menu items.

A selectable menu item.

A non-interactive group label within a dropdown menu.

A horizontal separator between dropdown menu sections.

A trailing keyboard-shortcut hint within a dropdown menu item.

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

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

Functions

hide_menu(id)

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

Hides the content panel with a leave transition. Used by the hook's data-on-close (Escape / Tab / outside click) and by menu items on select.

toggle_menu(id)

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

Toggles the content panel's visibility with enter/leave transitions. The ShadixDropdownMenu hook reacts to the resulting visibility change to position the menu and wire up keyboard/outside-click handling.