Dropdown
This component is used to create a dropdown under an element.
Showcase
<LnxDropdown>Open dropdown <template #content>
- Option 1
- Option 2
width
DropdownWidthHow wide the content is: as the element that opens it (`anchor`), at least as wide (`min-anchor`), or as its own content (`content`), aligned to the left of the element and kept inside the viewport Default value: "anchor"When to use
- For a panel anchored to an element: a menu of actions, filters or a small form.
- To pick a value from a list, use a Select, which already includes a dropdown with search.
- For content that needs the user's full attention, use a Modal.
Examples
Menu of actions
The dropdown doesn't open or close by itself: set is-open from your state, and close it when an option is picked or the user clicks outside. width="content" makes the panel as wide as its own content instead of as wide as the button.
vue
<LnxDropdown :is-open="isMenuOpen" width="content">
<LnxButton mode="outline" @click="isMenuOpen = !isMenuOpen">
Options
</LnxButton>
<template #content>
<LnxButton mode="clear" variant="grayscale" is-block @click="isMenuOpen = false">
Rename
</LnxButton>
<LnxButton mode="clear" variant="danger" is-block @click="isMenuOpen = false">
Delete
</LnxButton>
</template>
</LnxDropdown>1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
API
Props
| Prop | Type | Description |
|---|---|---|
is-open | boolean | Whether to show the dropdown Default: false |
offset-x | number | Horizontal offset of the dropdown Default: 0 |
offset-y | number | Vertical offset of the dropdown Default: 0 |
width | DropdownWidth | How wide the content is: as the element that opens it (anchor), at least as wide (min-anchor), or as its own content (content), aligned to the left of the element and kept inside the viewportDefault: "anchor" |
fit-content | boolean | Deprecated: use width="min-anchor"Default: false |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | The element that triggers the dropdown |
content | — | The content of the dropdown |
Types
DropdownWidth
ts
export const DROPDOWN_WIDTHS = {
ANCHOR: 'anchor', // As wide as the element that opens it
MIN_ANCHOR: 'min-anchor', // At least as wide as that element, wider if the content needs it
CONTENT: 'content', // The natural width of its content
} as const;
export type DropdownWidth = ValueOf<typeof DROPDOWN_WIDTHS>;1
2
3
4
5
6
2
3
4
5
6