Dropdown
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 astabindex="0"
. Both of these are necessary for the dropdown functionality.
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.