Dropdown
<afp-dropdown>
A dropdown component that displays a list of actions or options when triggered.
Examples #
Keep Open #
Dropdowns can remain open after selecting an item by adding the keep attribute to the <afp-dropdown> component.
Max Height #
You can set a maximum height for the dropdown using the --afp-dropdown-max-height CSS variable. If the content exceeds this height, a scrollbar will appear.
Min Width #
You can set a minimum width for the dropdown using the --afp-dropdown-min-width CSS variable.
Collaboration
Management
Notes #
The Dropdown component is built on top of the Popover component and therefore inherits many of its configuration options.
This includes properties like placement, offset, strategy, and duration, which control how and where the dropdown appears, how far it’s positioned from its trigger, the positioning strategy (absolute or fixed), and the transition timing for showing or hiding it.
For a detailed explanation of these options, see the Popover documentation.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keep
|
Set to true to keep the dropdown open after selecting an item.
Type
boolean
Default
false |
|
||||||||||||||||||||||||||
open
|
Indicates whether the dropdown is open.
Type
boolean
Default
false |
|||||||||||||||||||||||||||
strategy
|
Positioning strategy for the dropdown. Either `absolute` or `fixed`.
Type
AfpStrategy
Default
AfpStrategy.ABSOLUTE |
|||||||||||||||||||||||||||
offset
|
Offset configuration for positioning.
Type
AfpOffset
Default
{ mainAxis: 4, crossAxis: 0, alignmentAxis: 0, } |
|
||||||||||||||||||||||||||
duration
|
Animation duration in milliseconds.
Type
number
Default
150 |
|||||||||||||||||||||||||||
placement
|
The preferred placement of the dropdown panel. Note that the actual placement may vary as needed to keep the panel
inside of the viewport. If set to an empty array ([]), it enables auto placement. If containing more than two items,
it is automatically restricted to the provided placements. You can also input a space-separated string.
Type
AfpPlacement
Default
[ AfpPlacement.BOTTOM_START, AfpPlacement.BOTTOM_END, AfpPlacement.TOP_START, AfpPlacement.TOP_END, ] |
|
Methods
Learn more about using methods.
| Name | Description | Arguments |
|---|---|---|
show
|
Shows the dropdown.
|
- |
hide
|
Hides the dropdown.
|
- |
toggle
|
Toggles the dropdown open state.
|
- |
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-select
|
string
|
Emitted when a dropdown item is selected.
|
afp-show
|
void
|
Emitted when the dropdown is shown.
|
afp-after-show
|
void
|
Emitted after the dropdown has been shown.
|
afp-hide
|
void
|
Emitted when the dropdown is hidden.
|
afp-after-hide
|
void
|
Emitted after the dropdown has been hidden.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
default
|
The dropdown items (afp-dropdown-item).
|
trigger
|
The element that opens the dropdown.
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
base
|
The main wrapper element.
|
::part(base)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-dropdown-max-height
|
The maximum height of the dropdown panel.
|
15rem
|
--afp-dropdown-min-width
|
The minimum width of the dropdown panel.
|
auto
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/dropdown/dropdown.js';