Dropdown #
Dropdown component is a headless component that allow you to show some content near anchor. It is more utility component. You can use it with VaDropdownContent
or VaCard
component. This component looks like popover, but without any additional styling as VaPopover
has.
Default usage #
Placement and Offset #
You can place dropdown any direction you want. Offset is calculated relative to placement
prop. We use main
and cross
offset. Means main
will be relative to placement
direction while cross
is perpendicular. auto
placement will be bottom
by default, but will change to top
if it is not possible to display on bottom.
Offset direction | |
Placement: | |
Main: | |
Cross: |
Trigger #
You can use click
, hover
or none
trigger which will open dropdown. If you want dropdown to be opened only programmatically use none
trigger
Place on cursor #
You can render dropdown content on cursor position. It is useful to use cursor
props with auto-placement
so if content do not fit target it will be placed somewhere else.
Prevent overflow #
By default dropdown content is rendered as body child. This way we prevent any overflow. In example below overflow: hidden
of green box is ignored. But we still able to respec overflow by changing target
prop. In example below overflow: hidden
of red box is hiding dropdown content.
Props #
Name | Description | Types | Default |
---|---|---|---|
anchor | Anchor element. Dropdown will be opened when clicked on anchor. Can be |
| - |
anchorSelector | Anchor CSS selector instead of passing slot |
|
|
ariaLabel | Sets the |
|
|
autoPlacement | If dropdown doesn't fit viewport, it will be placed automatically to fit viewport |
|
|
closeOnAnchorClick | Dropdown will be closed when clicked on anchor |
|
|
closeOnClickOutside | Dropdown will be closed when clicked outside dropdown content and anchor |
|
|
closeOnContentClick | Dropdown will be closed when clicked inside dropdown content |
|
|
closeOnFocusOutside | Dropdown will be closed when focus is outside dropdown content and anchor |
|
|
contentClass |
|
| |
cursor | Dropdown will be rendered relative to cursor position |
|
|
disabled | Applies |
| - |
hoverOutTimeout | Time in |
|
|
hoverOverTimeout | Time in |
|
|
innerAnchorSelector | Anchor CSS selector inside passed slot |
|
|
isContentHoverable | If true, dropdown content will be hoverable |
|
|
keepAnchorWidth | If true, dropdown content will have exact same width as anchor |
|
|
keyboardNavigation | Enables keyboard navigation for the component. |
|
|
modelValue | The value of the |
|
|
offset | Dropdown content will be moved by main and cross axis according to current |
|
|
placement | Dropdown content will be placed on |
|
|
readonly | Doesn't look disabled, but acts like one. Mostly useful for wrapper components. |
| - |
role | The role attribute of the dropdown |
|
|
stateful | Add possibility to work with component without setting |
|
|
stickToEdges | Dropdown will not be rendered outside of viewport. It will be moved in opposite direction. |
|
|
target | Dropdown content parent. Dropdown content will be attached to |
| - |
teleport | Element where content will be rendered |
| - |
trigger | Action that will triggered when open and close dropdown. |
|
|
verticalScrollOnOverflow | If true, dropdown content will adjust its height when the content is larger than available space |
|
|
Events #
Name | Description |
---|---|
anchorClick | The event is triggered when anchor is clicked |
anchorDblclick | The event is triggered when anchor is double clicked |
anchorRightClick | The event is triggered when anchor is right clicked |
clickOutside | The event is triggered when clicked outside dropdown content and anchor |
close | The event is triggered when dropdown is closed |
contentClick | The event is triggered when clicked inside dropdown content |
focusOutside | The event is triggered when focus is outside dropdown content and anchor |
open | The event is triggered when dropdown is opened |
update:modelValue | The event is triggered when the component needs to change the model. Is also used by |
Slots #
Name | Description |
---|---|
anchor | Slot for anchor. When anchor is clicked, dropdown will be opened. Slot scope available:
|
default | Dropdown content. Slot scope available:
|
Css Variables #
Name | Default Value |
---|---|
--va-dropdown-line-height | 1 |
--va-dropdown-content-wrapper-z-index | var(--va-z-index-teleport-overlay, 9) |
--va-dropdown-display | inline-flex |