Fluxon.Components.Dropdown (Fluxon v1.0.20)

A comprehensive dropdown system for creating accessible, interactive menus and selection interfaces.

This component provides a flexible solution for building dropdown menus across your application. It offers a fully accessible implementation with keyboard navigation, automatic positioning, and proper focus management. The component is designed to work seamlessly with LiveView while maintaining proper accessibility standards.

Usage

Create a simple dropdown menu with default styling:

<.dropdown>
  <.dropdown_link navigate={~p"/profile"}>Profile</.dropdown_link>
  <.dropdown_link navigate={~p"/settings"}>Settings</.dropdown_link>
  <.dropdown_separator />
  <.dropdown_link href={~p"/logout"} method="delete">Sign Out</.dropdown_link>
</.dropdown>

Basic Dropdown

Custom Toggle

Replace the default button with a custom toggle element:

<.dropdown>
  <:toggle>
    <button class="flex items-center gap-x-2 bg-zinc-200/50 rounded-lg p-2">
      <img src={~p"/images/human-avatar-01.png"} alt="User" class="size-6 rounded-lg" />
      <div class="text-sm text-gray-800 font-semibold dark:text-gray-200">John Doe</div>
      <.icon name="u-chevron-down" class="size-4" />
    </button>
  </:toggle>
  <.dropdown_button>Profile</.dropdown_button>
  <.dropdown_button>Billing</.dropdown_button>
  <.dropdown_button>Settings</.dropdown_button>
</.dropdown>

Custom Toggle

Rich Content

Create complex dropdown interfaces with headers, separators, and custom content:

<.dropdown class="w-64">
  <.dropdown_custom class="flex items-center p-2">
    <img src="https://i.pravatar.cc/150?u=1" alt="Avatar" class="size-9 rounded-full" />
    <div class="flex flex-col ml-3">
      <span class="text-sm font-medium">Emma Johnson</span>
      <span class="text-xs text-zinc-500">emma@acme.com</span>
    </div>
  </.dropdown_custom>

  <.dropdown_separator />

  <.dropdown_header>Account</.dropdown_header>
  <.dropdown_link navigate={~p"/profile"}>Profile</.dropdown_link>
  <.dropdown_link navigate={~p"/billing"}>Billing</.dropdown_link>

  <.dropdown_header>Support</.dropdown_header>
  <.dropdown_link navigate={~p"/help"}>Documentation</.dropdown_link>
  <.dropdown_link navigate={~p"/contact"}>Contact Us</.dropdown_link>

  <.dropdown_separator />

  <.dropdown_link href={~p"/logout"} method="delete" class="text-red-600">
    Sign Out
  </.dropdown_link>
</.dropdown>

Rich Content

Hover Interaction

Enable hover-based opening with custom delays:

<.dropdown open_on_hover hover_open_delay={200} hover_close_delay={300}>
  <.dropdown_link navigate={~p"/profile"}>Profile</.dropdown_link>
  <.dropdown_link navigate={~p"/settings"}>Settings</.dropdown_link>
</.dropdown>

Menu Positioning

Control the dropdown's placement relative to its toggle:

<.dropdown placement="bottom-end">
  <.dropdown_link>Bottom End Aligned</.dropdown_link>
</.dropdown>

<.dropdown placement="right-start">
  <.dropdown_link>Right Side Menu</.dropdown_link>
</.dropdown>

Custom Animations

Customize the dropdown's enter/leave animations:

<.dropdown
  animation="transition-all duration-300"
  animation_enter="opacity-100 translate-y-0"
  animation_leave="opacity-0 -translate-y-2"
>
  <.dropdown_link>Smooth Slide Animation</.dropdown_link>
</.dropdown>

Keyboard Navigation

The component provides comprehensive keyboard support following ARIA best practices:

KeyElement FocusDescription
Tab/Shift+TabToggle buttonMoves focus to and from the dropdown toggle
Space/EnterToggle buttonOpens/closes the dropdown when focused
Toggle buttonOpens dropdown and highlights last item
Toggle buttonOpens dropdown and highlights first item
Menu itemMoves highlight to previous item
Menu itemMoves highlight to next item
Enter/SpaceMenu itemActivates the highlighted item
EscapeAnyCloses the dropdown

Focus Management

The dropdown implements sophisticated focus management to ensure a seamless user experience. Focus remains on the toggle button while users navigate through menu items using arrow keys. Menu items are not focusable through tab navigation, maintaining a streamlined keyboard interaction model. The component manages proper ARIA attributes to communicate the current selection to assistive technologies.

Positioning System

The dropdown menu intelligently positions itself relative to its toggle button. It automatically adjusts its placement based on available viewport space, ensuring optimal visibility regardless of the toggle button's position. The positioning system handles window resizing and scrolling, maintaining proper alignment in dynamic layouts.

Summary

Components

Renders a fully accessible dropdown menu with rich interaction support.

Renders a dropdown button item.

Renders a custom content area within the dropdown menu.

Renders a dropdown header.

Renders a dropdown link item.

Renders a dropdown separator.

Components