- Docs
- Popover
Popover Component
Learn how to implement the Popover component, powered by Flexipop for precise and flexible positioning.
The
Popover
component in the Flexilla library uses Flexipop, a positioning engine built specifically to handle element placements like popovers, tooltips, and dropdowns. Installation
To get started, install the
@flexilla/popover
package, or skip this step if you’ve already installed @flexilla/flexilla
. Structure
Popover Structure
-
popover-trigger
: Element that triggers the popover (e.g., on click or hover), with thedata-popover-trigger
anddata-popover-id
attributes. -
popover-content
: The content of the popover, with theid
attribute.
Example
this is content
Initializing the Component
To initialize the component, import
Popover
and create an instance: Options
The
Popover
component comes with a range of options to customize its behavior. Note: Some options can be passed throught data-* attributes
- defaultState :
data-default-state="Here the state"
- triggerStrategy :
data-trigger-strategy=""
Follow this for other too, exept for Callbacks and popper.
Event Effect Options
Example with Options
Trigger Strategies
The popover can be triggered via click or hover:
-
click
: Opens the popover on click. -
hover
: Opens the popover on hover.
Placement
The popover placement can be customized using the
placement
option, based on the positions provided by the Flexipop engine. Available placements:
-
top
,top-end
,top-start
-
bottom
,bottom-end
,bottom-start
-
left
-
right
Customizing the Offset
You can control the distance between the popover and the trigger element using
offsetDistance
: Attributes
Attributes options
-
data-placement
: define the placement of the popover -
data-offset-distance
: the equivalent of setting offsetDistance in options -
data-default-state
: define a default state of the popover (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 popover element: -
open
: Indicates the popover is currently visible. -
close
: Indicates the popover is hidden. You can use this to change the popover 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 Popover(/*options*/)
syntax Auto Initialization
You can automatically initialize all popovers on the page by calling
autoInit()
: The Popover component also exposes methods for programmatic control:
show()
Manually show the popover.
hide()
Manually hide the popover.
setShowOptions(/* options */)
Like
show()
method but here you can set the placement and offsetDistance if needed.