Dropdown extends Floater
Assign a floater panel to a MouseEvent
Example
new Dropdown({
content: createElement({
class: 'bg-white pad',
content: 'Hello World'
}),
anchor: '#hi-button'
})<komp-dropdown anchor="#hi-button">
Hello World
</komp-dropdown>Constructor
new Dropdown(options)
options
:
Object
optionalmouseevent
:
string
optionalMouseEvent that toggles floater
removeOnBlur
:
boolean
optionalHide dropdown when user clicks outside or focuses elsewhere
timeout
:
number
optionalMilliseconds to wait before hiding dropdown after mouseleave
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
onShow
:
function
optionalevent listener for show (cancellable, fires before showing)
onShown
:
function
optionalevent listener for shown (fires after showing)
onHide
:
function
optionalevent listener for hide (cancellable, fires before hiding)
onHidden
:
function
optionalevent listener for hidden (fires after hiding)
scope
:
string
optionalshowing a floater will hide all other floaters of same scope
content
:
string
|
HTMLElement
|
Array
|
Object
optionalcontent to append to element. Passed to Dolla's content
Instance Methods
Reassigning anchor on a floater that's already showing repositions it
to the new anchor — the autoUpdate loop follows along.
Bind floating-ui's autoUpdate loop to the current anchor, tearing down
any loop bound to a previous one. Called on connect and whenever anchor
changes while connected.
Hide the dropdown and remove -active class from the anchor
Parameters
eventOptions
:
Object
optionalCustomEvent options passed to the hide/hidden events
Returns
Dropdown
this
Replace the floater's content, keeping the arrow locator that the arrow
middleware holds a reference to. Use this rather than dolla's content(),
which replaces every child and would orphan the locator.
Parameters
Returns
Floater
this
Show the dropdown and add -active class to the anchor
Parameters
eventOptions
:
Object
optionalCustomEvent options passed to the show/shown events
Returns
Dropdown
this
Toggle the floater visibility
Parameters
shouldHide
:
boolean
optionalexplicitly show or hide. If omitted, toggles based on current visibility.
eventOptions
:
Object
optionalCustomEvent options passed to the resulting show/hide events
Returns
Floater
this
Events
hide
Fired before the floater is hidden (cancellable). When the floater is dismissed
in response to user input (Escape, outside click, mouseleave),
event.detail.sourceEvent is the originating event.
show
Fired before the floater is shown (cancellable). When the floater is shown in
response to user input, event.detail.sourceEvent is the originating event.
shown
Fired after the floater is shown. See Floater#show for detail.sourceEvent.