Dropdown

Defines different styles for a toggleable dropdown.

Dropdown

Defines different styles for a toggleable dropdown.

Usage

A dropdown is an example of the drop that provides its own styling. Any content, like a button, can toggle a dropdown. Just add the uk-dropdown attribute to a block element following the toggle.

<button type="button"></button>
<div uk-dropdown></div>

A dropdown can be enabled by hovering and clicking the toggle. Just add the mode: click option to the attribute to force click mode only. If you want to group the toggle and the dropdown, you can just add the .uk-inline class from the Utility component to a container element around both.

<div class="uk-inline">
    <button type="button"></button>
    <div uk-dropdown="mode: click"></div>
</div>

A dropdown can contain a nav from the Nav component. Just add the .uk-nav class and the .uk-dropdown-nav modifier to a <ul> element.

<button type="button"></button>
<div uk-dropdown>
    <ul class="uk-nav uk-dropdown-nav"></ul>
</div>

Grid in dropdown

You can place a grid from the Grid component inside a dropdown. Just wrap the content with a <div> element and add the uk-grid attribute. If the grid should stack automatically whenever the dropdown no longer fits its container, just add the .uk-dropdown-grid class.

<div class="uk-width-large" uk-dropdown>
    <div class="uk-dropdown-grid uk-child-width-1-2@m" uk-grid></div>
</div>

Use one of the classes from the Width component to adjust the dropdown’s width.


Large modifier

Add the .uk-dropdown-large class for a dropdown with larger padding.

<div class="uk-dropdown-large" uk-dropdown></div>

Position

By default, the dropdown is positioned below the toggle. To change its position, set the pos option to the uk-dropdown attribute. The first part of the value refers to the side where the dropdown is positioned, while the second part defines its alignment to the toggle.

PositionDescription
top-leftPositions the dropdown above the toggle and aligns it to the left.
top-centerPositions the dropdown above the toggle and aligns it to the center.
top-rightPositions the dropdown above the toggle and aligns it in the right.
bottom-leftPositions the dropdown below the toggle and aligns it to the left.
bottom-centerPositions the dropdown below the toggle and aligns it to the center.
bottom-rightPositions the dropdown below the toggle and aligns it in the right.
left-topPositions the dropdown to the left of the toggle and aligns it to the top.
left-centerPositions the dropdown to the left of the toggle and aligns it to the center.
left-bottomPositions the dropdown to the left of the toggle and aligns it to the bottom.
right-topPositions the dropdown to the right of the toggle and aligns it to the top.
right-centerPositions the dropdown to the right of the toggle and aligns it to the center.
right-bottomPositions the dropdown to the right of the toggle and aligns it to the bottom.
<div uk-dropdown="pos: top-left"></div>

Boundary

By default, the dropdown automatically changes its positions if it exceeds the viewport or any other parent scrolling ancestor. It will flip its position to the other side to prevent it from covering the toggle and shift its alignment to fit into the viewport. To set a different boundary other than the scrolling ancestors, just add the boundary: SELECTOR option to the uk-dropdown attribute using a selector for the boundary.

<div class="my-class">
    <button type="button"></button>
    <div uk-dropdown="boundary: !.my-class"></div>
</div>

Shift and Flip

To disable automatic shifting and flipping, add the shift: false or flip: false option to the uk-dropdown attribute.

<div uk-dropdown="shift: false; flip: false"></div>

Auto Update

By default, the drop repositions on scrolling. To disable dynamic positioning, add auto-update: false option to the uk-dropdown attribute. The dropdown will only be positioned once when opened.

<div uk-dropdown="auto-update: false"></div>

Target

By default, the dropdown is aligned to its toggle. To position the dropdown to a different element, just add target: SELECTOR option to the uk-dropdown attribute. To change just the side where the dropdown is positioned or the alignment to another element, use target-x: SELECTOR or target-y: SELECTOR.

<div class="my-class">
    <button type="button"></button>
    <div uk-dropdown="target: !.my-class"></div>
</div>

Inset

By default, the dropdown is positioned outside the toggle. To change the position to the inside, add the inset: true option to the uk-dropdown attribute. This option should only be used if the target option is also set so the dropdown doesn’t cover its toggle.

<div uk-dropdown="target: .my-class; inset: true"></div>

Stretch

To stretch the dropdown to fill the size of its closest scrolling ancestor, add the stretch: true option to the uk-dropdown attribute. To only stretch to one axis, use stretch: x or stretch: y. If the boundary option is set, the dropdown stretches to the defined boundary.

<div uk-dropdown="stretch: true"></div>

Animation

Apply one or more animations to the dropdown by adding the animation: uk-animation-* option with one of the classes from the Animation component. You can also determine the animation’s duration. Just add the duration option with a value in milliseconds. Set animate-out: true to also show an animation when closing the drop.

<div uk-dropdown="animation: uk-animation-slide-top-small; duration: 1000"></div>

Alternatively, the Drop component has two additional animation types which are not covered by the Animation component. slide-* animations slide the dropdown and its content from a selected direction, while with the reveal-* animations, the content of the dropdown stays static and is revealed from a selected direction.

AnimationDescription
slide-topSlides the dropdown from the top.
slide-bottomSlides the dropdown from the bottom.
slide-leftSlides the dropdown from the left.
slide-rightSlides the dropdown from the right.
reveal-topReveals the dropdown from the top.
reveal-bottomReveals the dropdown from the bottom.
reveal-leftReveals the dropdown from the left.
reveal-rightReveals the dropdown from the right.
<div uk-dropdown="animation: slide-top; animate-out: true"></div>

Offset

To define a custom offset between the dropdown and its toggle, add the offset option with a value in pixels.

<div uk-dropdown="offset: 80"></div>

Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

OptionValueDefaultDescription
toggleCSS selector- *CSS selector for the element to be used as toggle. By default, the preceding element.
posStringbottom-leftDrop position.
stretchBoolean, x, ytrueStretch dropdown on both (true) or given axis.
modeclick, hoverclick, hoverComma-separated list of dropdown trigger behavior modes.
delay-showNumber0Delay time in hover mode before a dropdown is shown in ms.
delay-hideNumber800Delay time in hover mode before a dropdown is hidden in ms.
auto-updateBooleantrueDisable dynamic positioning while scrolling by setting this option to false.
boundaryCSS selectorfalseThe area the dropdown can’t exceed causing it to flip and shift. By default, the nearest scrolling ancestor.
targetBoolean, CSS selectorfalseThe element the dropdown is positioned to (true for window).
target-xBoolean, CSS selectorfalseThe element’s X axis the dropdown is positioned to (true for window).
target-yBoolean, CSS selectorfalseThe element’s Y axis the dropdown is positioned to (true for window).
insetBooleanfalsePosition inside its target.
flipBooleantrueFlip the dropdown along the main axis if it overflows the boundary.
shiftBooleantrueShift the dropdown along the cross axis if it overflows the boundary.
offsetNumber0The dropdown offset.
animationStringuk-animation-fadeSpace-separated names of animations. Comma-separated for animation out.
animation-outBooleanfalseUse animation when closing the drop.
bg-scrollBooleantrueAllow background scrolling while dropdown is opened.
durationNumber200The animation duration.
containerBooleanfalseDefine a target container via a selector to specify where the dropdown should be appended in the DOM.

JavaScript

Learn more about JavaScript components.

Initialization

UIkit.dropdown(element, options);

Events

The following events will be triggered on elements with this component attached:

NameDescription
toggleFires before an item is toggled.
beforeshowFires before an item is shown. Can prevent showing by calling preventDefault() on the event.
showFires after an item is shown.
shownFires after the item’s show animation has completed.
beforehideFires before an item is hidden. Can prevent hiding by calling preventDefault() on the event.
hideFires before an item is hidden.
hiddenFires after an item is hidden.
stackFires when the drop-stackclass is applied.

Methods

The following methods are available for the component:

Show

UIkit.dropdown(element).show();

Shows the dropdown.

Hide

UIkit.dropdown(element).hide(delay);

Hides the dropdown.

NameTypeDefaultDescription
delayBooleantrueDelay hiding the Dropdown.