Dropdown
The Dropdown component displays specific content in a pop-up control. It is often used in conjunction with the Menu component.
Usage
Import the component:
import 'mdui/components/dropdown.js';
Import the TypeScript type:
import type { Dropdown } from 'mdui/components/dropdown.js';
Example:
<mdui-dropdown>
<mdui-button slot="trigger">open dropdown</mdui-button>
<mdui-menu>
<mdui-menu-item>Item 1</mdui-menu-item>
<mdui-menu-item>Item 2</mdui-menu-item>
</mdui-menu>
</mdui-dropdown>
Open Position
Set the placement
attribute to control the dropdown's open position.
Trigger Method
Set the dropdown's trigger method with the trigger
attribute.
Open on Pointer
Add the open-on-pointer
attribute to open the dropdown at the pointer location. This is often combined with trigger="contextmenu"
for right-click menu activation.
Keep Menu Open
By default, clicking a menu item in the dropdown component closes it. Add stay-open-on-click
to keep it open.
Open/Close Delay
With trigger="hover"
, use open-delay
and close-delay
to set the open and close delays.
API
Properties
Attribute | Property | Reflect | Type | Default |
---|---|---|---|---|
open | open | boolean | false | |
Opens the dropdown. | ||||
disabled | disabled | boolean | false | |
Disables the dropdown. | ||||
trigger | trigger | 'click' | 'hover' | 'focus' | 'contextmenu' | 'manual' | string | 'click' | |
Defines the trigger method for the dropdown. Supports multiple space-separated values. Possible values:
| ||||
placement | placement | 'auto' | 'top-start' | 'top' | 'top-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end' | 'auto' | |
Sets the position of the dropdown. Possible values:
| ||||
stay-open-on-click | stayOpenOnClick | boolean | false | |
Keeps the dropdown open after clicking an | ||||
open-delay | openDelay | number | 150 | |
Sets the delay (in ms) for opening the dropdown on hover. | ||||
close-delay | closeDelay | number | 150 | |
Sets the delay (in ms) for closing the dropdown on hover. | ||||
open-on-pointer | openOnPointer | boolean | false | |
Opens the dropdown at the cursor position. This is typically used for context menus. |
Events
Name |
---|
open |
Emitted when the dropdown starts to open. Can be prevented with |
opened |
Emitted after the dropdown has opened and the animations are completed. |
close |
Emitted when the dropdown starts to close. Can be prevented with |
closed |
Emitted after the dropdown has closed and the animations are completed. |
Slots
Name |
---|
(default) |
The content of the dropdown. |
trigger |
The element that triggers the dropdown, such as an |
CSS Custom Properties
Name |
---|
--z-index |
The CSS |