Dropdown

Dropdown is a contextual menu component for exposing actions, navigation links, filters, or compact panels from a trigger. It is initialized globally by FrontAlign and uses event delegation, so no per-dropdown instance is required.

The component keeps the public API consistent with the FrontAlign attribute system: fa-toggle="dropdown" is used for delegated triggers, while optional behavior modes can be configured with fa-trigger.

Dropdown is suited for account menus, toolbar actions, navigation groups, select-like action menus, settings panels, and any interface that needs compact contextual content.


Getting Started

Add .dropdown to the root element, place a trigger inside it, and mark the trigger with fa-toggle="dropdown". The menu should use .dropdown-menu, and menu content should be wrapped with .dropdown-content.

<div class="dropdown">
  <button
    class="button is-primary"
    type="button"
    fa-toggle="dropdown"
    aria-haspopup="menu"
    aria-expanded="false">
    Options
  </button>

  <div class="dropdown-menu" role="menu">
    <div class="dropdown-content">
      <a class="dropdown-item" href="#">Profile</a>
      <a class="dropdown-item" href="#">Settings</a>
      <hr class="dropdown-divider"/>
      <a class="dropdown-item" href="#">Sign out</a>
    </div>
  </div>
</div>

Structure

Dropdown markup is intentionally small: a root, a trigger, a menu, and optional content helpers.

ElementClass / AttributePurpose
RootdropdownWraps the trigger and menu. The open state is applied here.
Triggerfa-toggle="dropdown"Marks the clickable element that opens or closes the dropdown.
Menudropdown-menuThe positioned popup panel shown when the dropdown is active.
Content wrapperdropdown-contentGroups links, buttons, dividers, headers, or custom interactive content.
Menu itemdropdown-itemStyles a selectable link or button inside the menu.
Dividerdropdown-dividerVisually separates groups of menu items.
Headerdropdown-headerDisplays a non-interactive section label inside the menu.
Open stateis-activeAdded and removed automatically by JavaScript.

Open With Hover

Use a button as the trigger when the dropdown performs an action or opens an action menu. Use links inside the menu for navigation. Add data-trigger attribute to root element.

<div className="dropdown"data-dropdown-trigger="hover">
  <button
    className="button is-primary"
    type="button"
    fa-toggle="dropdown"
    aria-haspopup="menu"
    aria-expanded="false"
  >With Hover</button>

<div className="dropdown-menu" role="menu">
  <div className="dropdown-header">Account</div>
  <div className="dropdown-item">
    <a className="link" href="#">Profile</a>
  </div>
  <div className="dropdown-header">Settings</div>
  <div className="dropdown-item">
    <a className="link" href="#">Preferences</a>
  </div>
  <div className="dropdown-item">
    <a className="link" href="#">Sign out</a>
  </div>
</div>
</div>

Alignment

Dropdown menus open below the trigger by default. Add alignment modifiers to the root .dropdown when the menu should align differently.

ClassBehaviorUse case
dropdownOpens below and aligns to the start edge.Default menus and toolbar actions.
is-endAligns the menu to the end edge of the trigger.Account menus, navbar actions, right-side toolbars.
is-centerCenters the menu relative to the trigger.Compact icon menus or centered navigation actions.
<!-- Start aligned by default -->
<div class="dropdown">...</div>

<!-- End aligned -->
<div class="dropdown is-end">...</div>

<!-- Center aligned -->
<div class="dropdown is-center">...</div>

Direction Variants

Use direction modifiers on the root .dropdown to control where the menu opens.

ClassDirectionDescription
is-drop-upUpOpens above the trigger.
is-drop-endEndOpens beside the trigger toward the inline end side.
is-drop-startStartOpens beside the trigger toward the inline start side.
<div class="dropdown is-drop-up">...</div>
<div class="dropdown is-drop-end">...</div>
<div class="dropdown is-drop-start">...</div>

Scrollable Content

When the menu contains many items, .dropdown-content acts as a scroll container. Set a max-height to cap the visible area and enable vertical scrolling for overflow.

  <div className="dropdown-menu" role="menu">
    <div className="dropdown-content">
      <span className="dropdown-header">Pages</span>
      <a className="dropdown-item is-active" href="#">Dashboard</a>
      <a className="dropdown-item" href="#">Analytics</a>
      <a className="dropdown-item" href="#">Projects</a>
      <a className="dropdown-item" href="#">Team</a>
      <hr className="dropdown-divider" />
      <span className="dropdown-header">Account</span>
      <a className="dropdown-item" href="#">Profile</a>
      <a className="dropdown-item" href="#">Settings</a>
      <a className="dropdown-item" href="#">Billing</a>
      <hr className="dropdown-divider" />
      <a className="dropdown-item" href="#">Sign out</a>
    </div>
  </div>
</div>

Arrow Indicator

Add .has-arrow to .dropdown-trigger when you want a CSS-only arrow next to the trigger. The arrow direction follows the dropdown placement modifiers.

<div class="dropdown is-end">
  <div class="dropdown-trigger has-arrow">
    <button
      class="button"
      type="button"
      fa-toggle="dropdown"
      aria-haspopup="menu"
      aria-expanded="false"
    >
      More
    </button>
  </div>

  <div class="dropdown-menu" role="menu">
    <div class="dropdown-content">
      <a class="dropdown-item" href="#">Edit</a>
      <a class="dropdown-item" href="#">Duplicate</a>
      <a class="dropdown-item" href="#">Archive</a>
    </div>
  </div>
</div>
PlacementArrow direction
dropdown / is-end / is-centerDown
is-drop-upUp
is-drop-endEnd
is-drop-startStart

Runtime Behavior

Dropdown is a delegated component. One global listener handles every dropdown trigger on the page.

InteractionBehavior
Trigger clickCloses other dropdowns, then toggles the clicked dropdown.
Outside clickCloses all open dropdowns.
Menu clickKeeps the dropdown open, except when the clicked target is an <a>.
Escape keyCloses all active dropdowns.
Hover modeOpens on hover only on devices matching (hover: hover) and (pointer: fine).
ARIA syncUpdates aria-expanded on the trigger whenever the dropdown opens or closes.

React Usage

For most React and Next.js projects, initialize FrontAlign once in a client component and use the same markup in MDX or JSX. The dropdown behavior is delegated, so dynamically rendered dropdowns still work.

'use client';

import { useEffect } from 'react';
import { useDropdown } from 'frontalign';

export default function Navbar(){
  useDropdown();
  return (

  )
}

Accessibility

Dropdown manages aria-expanded automatically, but the trigger should still include popup semantics. For the strongest accessibility, connect the menu to the trigger with aria-labelledby.

<div class="dropdown">
  <button
    id="account-dropdown-trigger"
    class="button"
    type="button"
    fa-toggle="dropdown"
    aria-haspopup="menu"
    aria-expanded="false"
  >
    Account
  </button>

  <div
    class="dropdown-menu"
    role="menu"
    aria-labelledby="account-dropdown-trigger"
  >
    <div class="dropdown-content">
      <a class="dropdown-item" role="menuitem" href="/profile">Profile</a>
      <a class="dropdown-item" role="menuitem" href="/settings">Settings</a>
    </div>
  </div>
</div>
AttributeRequiredPurpose
aria-expandedRecommendedAutomatically updated by FrontAlign to reflect open or closed state.
aria-haspopup="menu"RecommendedTells assistive technology that the trigger opens a menu popup.
aria-labelledbyOptionalLabels the menu using the trigger text. Useful, but not required for runtime behavior.
role="menu"OptionalUse when the dropdown represents an application-style action menu.

Class Reference

Class / AttributeTypeDescription
dropdownRootBase dropdown wrapper.
dropdown-menuElementPopup container.
dropdown-contentElementInner content surface for items and groups.
dropdown-itemElementMenu item class for links or buttons.
dropdown-headerElementNon-interactive group label.
dropdown-dividerElementVisual separator.
has-arrowModifierAdds a CSS-only arrow to the trigger wrapper.
is-activeStateOpen state managed by JavaScript.
is-endModifierAligns the menu to the end side.
is-centerModifierCenters the menu relative to the trigger.
is-drop-upModifierOpens the menu upward.
is-drop-endModifierOpens the menu toward the inline end side.
is-drop-startModifierOpens the menu toward the inline start side.
fa-toggle="dropdown"AttributeDelegated dropdown trigger marker.
data-trigger="hover"AttributeOptional root behavior mode for hover-open dropdowns.

Notes

Use fa-toggle="dropdown" instead of data-toggle="dropdown" to keep the FrontAlign API consistent with fa-component, fa-theme, and other framework-level attributes.

aria-labelledby is not required for the dropdown to work, but it is recommended when the menu should be announced using the trigger label. Keep aria-expanded on the trigger because FrontAlign updates it automatically.

FrontAlign