Floater extends KompElement
Render content on a layer above an anchored element.
Example
new Floater({
content: "Hello World",
anchor: '#hi-button'
})<komp-floater anchor="#hi-button">
Hello World
</komp-floater>Constructor
new Floater(options)
options
:
Object
optionalcontent
:
string
|
HTMLElement
|
Array
|
Object
optionalcontent for the floater, uses Dolla's content
anchor
:
HTMLElement
element to anchor positioning to
container
:
string
|
HTMLElement
optionalelement to append floater to. If String, then used as selector for this.closest(selector)
placement
:
string
optionalhow the floater is anchored, e.g. "top", "top-start", "top-end", "left", "left-start"...
strategy
:
string
optionalhow the floater is positioned in the document. "absolute" or "fixed"
flip
:
boolean
|
Object
optionalSee https://floating-ui.com/docs/flip, defaults to false in favor of autoPlacement
arrow
:
boolean
|
number
optionalTrue to show default size, or number in pixels
removeOnBlur
:
boolean
optionalhide floater on outside click/focus or escape key
timeout
:
number
optionalms to wait until hiding after mouseout
onHide
:
function
optionalcalled after hidden
onShow
:
function
optionalcalled before showing
scope
:
string
optionalshowing a floater will hide all other floaters of same scope
Properties
showing
:
boolean
is floater showing, can be disconnected and not showing in case of Tooltip
Instance Properties
Attributes settable via constructor options
Methods overridable via constructor options
Methods to auto-bind to this
Event names that can be bound via onEventName constructor options
CSS injected once per component via adoptedStyleSheets
Attributes to observe for changes. Triggers changed(attribute, was, now) and [attribute]Changed(was, now) callbacks.
Instance Methods
Listen for events on another element, automatically cleaned up when this component disconnects
Parameters
element
:
HTMLElement
element to listen on
eventType
:
string
event type
args
:
*
additional arguments passed to addEventListener
Called every time an observed attribute changes. Attribute must be listed in static watch.
Parameters
attribute
:
string
the attribute that changed
was
:
*
previous value
now
:
*
new value
Called when element is connected to the DOM
Called when element is disconnected from the DOM
Called once per instantiation, but only after element is connected to the DOM
Remove element. Fires beforeRemove, calls optional callback, removes from DOM, then fires afterRemove.
Parameters
callback
:
function
optionalasync callback called between beforeRemove and afterRemove
Returns
KompElement
this
Toggle the floater visibility
Parameters
shouldHide
:
boolean
optionalexplicitly show or hide. If omitted, toggles based on current visibility.
Returns
Floater
this
Trigger an event on this element
Parameters
eventName
:
string
event name to trigger
args
:
*
additional arguments
Events
Fired after the element is connected to the DOM and initialized
Fired after the element is disconnected from the DOM
Fired after the element is removed
Fired before the element is connected to the DOM
Fired before the element is disconnected from the DOM
Fired before the element is removed
shown
Fired when the floater is shown
Notes
Transition Animation
The floater will follow the transition effects set by CSS, and adds classes
-out, -out-start, -in and -in-start when hiding and showing.
Additionally, the floater adds classes for placement -left, -right, -top, -bottom.