Dropdown API
JavaScript API
Global Helper: window.Dropdowns
window.Dropdowns.getAll(): Returns an array of all initialized Dropdown instances.window.Dropdowns.findById(idOrDomId): Finds a specific instance by its numeric ID or DOM ID (e.g.,dropdown-1).
Instance Methods
If you have a reference to a dropdown instance, you can call these methods:
instance.open({ cascade: true }): Opens the dropdown.instance.close({ cascade: true }): Closes the dropdown.instance.toggle({ cascade: true }): Toggles the open state.
Custom Events
Events are dispatched from the main [data-menu-element="dropdown"] element and bubble up.
menuDropdown:open
Fired when the dropdown opens.
menuDropdown:close
Fired when the dropdown closes.
menuDropdown:modeChange
Fired when the component switches between dropdown, accordion, or stacked modes.
menuDropdown:open:[mode]
Specific open event (e.g., menuDropdown:open:dropdown).
menuDropdown:close:[mode]
Specific close event (e.g., menuDropdown:close:stacked).
Event Detail (event.detail):
instanceId: The unique numeric ID of the dropdown.mode: The current mode (dropdown,accordion, orstacked).level: The nesting level (0 for top-level).
Examples
Programmatic Control
Listening for Events
Detecting Mode Changes
Working with Nested Dropdowns
Last updated