- Docs
- Dropdown
Accordion Component
Create interactive, collapsible accordion elements with customizable options and animations.
The
Dropdown
component in Flexilla provides a versatile and customizable way to create dropdown menus. It is built on top of the Popover component, leveraging the powerful Flexipop positioning engine to ensure precise element placement. Installation
To start using the dropdown component, install the
@flexilla/dropdown
package. If you’ve already installed the @flexilla/flexilla
, this step can be skipped. Structure
The dropdown consists of a trigger and the dropdown content.
Dropdown Trigger
Any valid HTMLElement, but it’s recommanded to use button.
-
data-dropdown-trigger
: This attribute is added to the element that will trigger the dropdown. -
data-dropdown-id
: This attribute must correspond to the ID of the dropdown content element.
Dropdown Content
Any Valid HTMLElement, must have
id
attribute, position set to fixed. Example
Johnkat MJ
FrontEnd DesignerInitializing the Component
To initialize the dropdown, import the
Dropdown
component and create an instance: Options
The
Dropdown
component provides several configuration options to control its behavior. Event Effect Options
Example with Options
Trigger Strategies
You can customize how the dropdown is triggered using the
triggerStrategy
option: - click: Opens the dropdown on click.
- hover: Opens the dropdown on hover.
Placement
Similar to the Popover component, you can control where the dropdown appears using the
placement
option. Available placements:
-
top
-
bottom
-
left
-
right
Customizing the Offset
You can adjust the spacing between the dropdown trigger and the dropdown content using the
offsetDistance
option: Attributes
Attributes options
-
data-placement
: define the placement of the Dropdown -
data-offset-distance
: the equivalent of setting offsetDistance in options -
data-default-state
: define a default state of the Dropdown (open|close), the equivalent ofoptions.defaultState
, must be (open|close) -
data-prevent-close-outside
: adding this attribute is similar to setting the optionpreventFromCloseOutside
, no value required -
data-prevent-close-inside
: adding this attribute is similar to setting the optionpreventCloseFromInside
, no value required
data-state
Attribute
The
data-state
attribute is used to indicate the state of the dropdown element: -
open
: Indicates the dropdown is currently visible. -
close
: Indicates the dropdown is hidden. You can use this to change the dropdown Element behavior with CSS (hide, show)
aria-expanded
Attribute
The
aria-expanded
attribute indicate if the trigger is expanded or not, if expanded true then normal the data-state is open too. You use it in CSS like to animate the indicator inside the trigger or something else
Methods
init(/*options*/)
You can use the Static method if you don’t like to use
new Dropdown(/*options*/)
syntax Auto Initialization
You can automatically initialize all Dropdowns on the page by calling
autoInit()
: The Dropdown component also exposes methods for programmatic control:
show()
Manually show the dropdown.
hide()
Manually hide the dropdown.
setShowOptions(/* options */)
Like
show()
method but here you can set the placement and offsetDistance if needed.