Dropdown menus are hidden by default and can contain action lists with only a few items or more complicated filter or menu systems. Typically a button will show and hide them, though other components may also be used as a trigger.
Use them anywhere a set of links or controls do not need to be available on screen by default, when you need to show overflow controls, or when you have a complicated menu that does not rise to the level of a modal or drawer.
Basic dropdown
To create a dropdown, simply place both .hc-dropdown-toggle and .hc-dropdown-content elements inside of a parent .hc-dropdown.
The triggering element must currently be a <div> with class .hc-dropdown-toggle-button. You can turn this into a button by adding the same button classes as a regular button would get, but please note that the element itself has to be a <div>.
Important note
The dropdown toggle must unfortunately be a <div> due to an ongoing bug in Safari that prevents a <button> element from receiving focus.
This is still accessible and compliant, just give it role="button" as well as tabindex="0". Both of these are necessary for the dropdown functionality.
Future deprecation note
Now that the Popover API has full browser support, once anchor positioning also becomes widely available we will replace the current focus-within handling with the new native popover handling. Safari and Firefox remain to implement this, expected 2025.
JavaScript alternative handling
If you’d prefer to handle the dropdown show/hide yourself via JavaScript, append .hc-dropdown--js to the parent dropdown component and then manually add or remove the class .hc-dropdown--is-visible to this element.
Honeycomb handles the display and animation, but you will be responsible for any click handlers to add or remove this display class.
Interactions and states
Dropdowns have a subtle default fade-in and slide-up animation on reveal, with the reverse on hide. They have a default drop shadow as well. All of this is handled natively.
No javascript is required! As of v0.2.5 all dropdown interactions are now handled by CSS only. The parent .hc-dropdown element uses the :focus-within pseudo-class: when the triggering button gets focus, visibility and opacity styles are applied to the .hc-dropdown-content. Because it uses :focus-within, user actions inside of the dropdown itself do not cause it to close.
It’s important that the .hc-dropdown-toggle-button element is inside of an .hc-dropdown-toggle element. The later is used to maintain cursor: pointer; on the button when the dropdown is open.
The dropdown will close when the user clicks outside of it.
Dropdown button with caret
There is a special button variation specifically for dropdowns! This variation is used in the header for both the primary dropdown menus as well as the account menu dropdown.
Apply .hc-button--dropdown to get the basic effect. There are specific child elements and classes for content and the caret as well; content inside should have .hc-button--dropdown--content and the caret must be a <sub> element with class .hc-button--dropdown--caret.
Toggle direction
Dropdowns open centered to the toggle button by default. You can control this direction with utility classes; currently right-justified and left-justified are supported.
Dropdown menus
Honeycomb has a few common preset dropdown menu systems available. Included are a standard context menu, the user menu triggered from the Header, and a stacked layout that can contain top, scrollable middle, and bottom content sections.
In general, create the dropdown with the same set of dropdown classes as documented above. If you have only one menu, this can be the same .hc-dropdown-content element.
If you have a more complicated menu or more than one menu, wrap them all inside of a <div> that is instead the .hc-dropdown-content wrapper element. Each menu inside the dropdown should then use a <menu> element with various classes for the different menu systems documented below.
Context menu
Context menus offer a small set of actions or links inside of a dropdown menu. Add the class .hc-dropdown-menu and the modifier .hc-dropdown-menu--context to the <menu> element. Place menu items inside this element.
To include fixed space for an icon within each menu item, even when you don’t provide an icon for alignment purposes, add the modifer .hc-dropdown-menu--with-icons. Likewise, add .hc-dropdown-menu--with-indicators for the right side indicator space.
If you’d like to include an indicator or count indicator, make that the final element inside of the link.
User menu
The user account dropdown menu opened from the Header also exists as a preconfigured component here. Append the classes .hc-dropdown-menu .hc-dropdown-menu--account to the first <menu> element. Avatar is an optional include if your app uses user avatars.
Menu items below the upper account info section use a pair of context menus, documented above.
Stacked menu
A stacked dropdown menu has preconfigured title, content, and footer sections. The content section has a max height of 320rem (or 33% of the viewport height, whichever is less), and will scroll on overflow. The title and footer sections are fixed and always present if included.
This is usful for a combobox where you’d like a text input stuck to the top that filters a selectable list, with a fixed position CTA button at the bottom.