overlays
Tailwind CSS Dropdown
The Dropdown neatly displays Dropdown or content using a JavaScript plugin, offering a compact interface for easy navigation and space-saving.
Class Name | Type | Description |
---|---|---|
dropdown | Component | Container for the dropdown. |
dropdown-toggle | Component | Toggle button for the dropdown. |
dropdown-menu | Component | Container for the dropdown menu. |
dropdown-toggle-wrapper | Modifier | A wrapper for a Dropdown toggle, this is useful when some other element is placed in the Dropdown toggle. For example. if you want to place a “+” button inside an existing Dropdown toggle button that opens a modal. |
dropdown-item | Modifier | Styles applied to individual dropdown items. |
vertical-scrollbar | Modifier | Applies overflow-y-auto and custom styling to scrollbar. |
dropdown-open:{tw-utility-class} | Modifier | Modifies tailwind classes when the dropdown menu is open. |
dropdown-close | Modifier | Dropdown close element (can be multiple). |
dropdown-header | Modifier | Adds a header to the dropdown. |
dropdown-footer | Modifier | Adds a footer to the dropdown. |
dropdown-title | Modifier | Adds a title to the dropdown. |
active | Modifier | Applies active styling to dropdown items. |
disabled | Modifier | Applies disabled styling to dropdown items. |
Basic dropdown example.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-default" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-default">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Use dropdown-header
class to display extra information separately from the menu items in the dropdown.
John Doe
jhon@doe.com- My Profile
- Settings
- Billing
- FAQs
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-header" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown header
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-header">
<li class="dropdown-header gap-2">
<div class="avatar">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-2.png" alt="User Avatar" />
</div>
</div>
<div>
<h6 class="text-base-content/90 text-base font-semibold">John Doe</h6>
<small class="text-base-content/50 text-sm font-normal">jhon@doe.com</small>
</div>
</li>
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Use the dropdown-footer
class to present additional information distinct from the dropdown menu items, at the
bottom.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-footer" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown footer
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-footer">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
<li class="dropdown-footer gap-2">
<button class="btn btn-error btn-soft btn-block">Sign out</button>
</li>
</ul>
</div>
Use dropdown-title
class to present titile for the dropdown content.
- Settings
- My Profile
- Settings
- Billing
- FAQs
- Contact
- Contact support
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-title" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown title
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-title">
<li class="dropdown-title">Settings</li>
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
<hr class="border-base-content/25 my-2 -mx-2" />
<li class="dropdown-title">Contact</li>
<li><a class="dropdown-item" href="#">Contact support</a></li>
</ul>
</div>
Using form within a dropdown menu.
<div class="dropdown relative inline-flex [--auto-close:inside] rtl:[--placement:bottom-end]">
<button id="dropdown-form" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown form
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 min-w-70 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-form">
<form class="p-4">
<label class="form-control mb-3">
<div class="label">
<span class="label-text">Username</span>
</div>
<input type="text" placeholder="Johndoe" class="input" />
</label>
<label class="form-control mb-4">
<div class="label">
<span class="label-text">Password</span>
</div>
<input type="password" placeholder="············" class="input" autocomplete="password" />
</label>
<button type="submit" class="btn btn-primary btn-block">Sign in</button>
</form>
</div>
</div>
Put radio inside dropdown-item
. Make the dropdown item appear with radio.
<div class="dropdown relative inline-flex [--auto-close:inside] rtl:[--placement:bottom-end]">
<button id="dropdown-transportation" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown radio
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-transportation">
<div class="dropdown-item gap-4">
<input id="dropdown-radio-car-2" name="dropdown-item-radio" type="radio" class="radio radio-primary" checked/>
<label for="dropdown-radio-car-2">
<span class="text-base-content/90 block text-sm font-semibold">Car</span>
</label>
</div>
<div class="dropdown-item gap-4">
<input id="dropdown-radio-bicycle-2" name="dropdown-item-radio" type="radio" class="radio radio-primary" />
<label for="dropdown-radio-bicycle-2">
<span class="text-base-content/90 block text-sm font-semibold">Bicycle</span>
</label>
</div>
</div>
</div>
Put checkbox inside dropdown-item
. Make the dropdown item appear with checkbox.
<div class="dropdown relative inline-flex [--auto-close:inside] rtl:[--placement:bottom]">
<button id="dropdown-checkbox" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown checkbox
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-checkbox">
<label class="dropdown-item cursor-pointer items-start gap-4 max-sm:px-2">
<input type="checkbox" class="checkbox checkbox-primary mt-2" checked />
<div class="label flex-col items-start">
<span class="label-text font-semibold">Mark as important</span>
<span class="label-text-alt text-base-content/50">Notify me when this action happens.</span>
</div>
</label>
<label class="dropdown-item cursor-pointer items-start gap-4 max-sm:px-2">
<input type="checkbox" class="checkbox checkbox-primary mt-2" />
<div class="label flex-col items-start">
<span class="label-text font-semibold">Share with team</span>
<span class="label-text-alt text-base-content/50">Notify me when this action happens.</span>
</div>
</label>
</div>
</div>
Put switch inside dropdown-item
. Make the dropdown item appear with switch.
<div class="dropdown relative inline-flex [--auto-close:inside] rtl:[--placement:bottom-end]">
<button id="dropdown-checkbox" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown switch
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 min-w-60 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-checkbox">
<label class="dropdown-item items-start gap-4">
<input type="checkbox" class="switch switch-primary mt-2" checked />
<span class="label cursor-pointer flex-col items-start">
<span class="label-text text-base">Notifications</span>
<span class="text-neutral text-sm">Receive push notifications</span>
</span>
</label>
<label class="dropdown-item items-start gap-4">
<input type="checkbox" class="switch switch-primary mt-2" />
<span class="label cursor-pointer flex-col items-start">
<span class="label-text text-base">Location Services</span>
<span class="text-neutral text-sm">Allow access to your location</span>
</span>
</label>
<label class="dropdown-item items-start gap-4">
<input type="checkbox" class="switch switch-primary mt-2" checked />
<span class="label cursor-pointer flex-col items-start">
<span class="label-text text-base">Dark Theme</span>
<span class="text-neutral text-sm">Enable dark theme for the app</span>
</span>
</label>
</div>
</div>
Create nested dropdowns by adding a dropdown within a dropdown.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="nested-dropdown" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="nested-dropdown">
<li><a class="dropdown-item" href="#">Send My Profile</a></li>
<li><a class="dropdown-item" href="#">View Settings</a></li>
<li class="dropdown relative [--offset:15] max-sm:[--placement:bottom-start] [--placement:right-start]">
<button id="nested-dropdown-2" class="dropdown-toggle dropdown-item justify-between" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
More Options
<span class="icon-[tabler--chevron-right] size-4 rtl:rotate-180"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="nested-dropdown-2">
<li><a class="dropdown-item" href="#">Download Documents</a></li>
<li><a class="dropdown-item" href="#">Manage FAQs</a></li>
</ul>
</li>
<li><a class="dropdown-item" href="#">Logout</a></li>
</ul>
</div>
Use the menu icon trigger element on components such as cards as an alternative element to the button.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-menu-icon" type="button" class="dropdown-toggle btn btn-square btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
<span class="icon-[tabler--dots-vertical] size-6"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-menu-icon">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Demonstration of a split dropdown.
<div class="join">
<button type="button" class="btn btn-outline btn-primary join-item">Dropdown</button>
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-split" type="button" class="dropdown-toggle btn btn-square btn-primary join-item" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-split">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
</div>
Dropdown with avatar.
John Doe
jhon@doe.com- My Profile
- Settings
- Billing
- FAQs
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-avatar" type="button" class="dropdown-toggle btn btn-outline btn-primary flex items-center gap-2 rounded-full" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
<div class="avatar">
<div class="size-6 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-3.png" alt="User Avatar" />
</div>
</div>
John Doe
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-avatar">
<li class="dropdown-header gap-3">
<div class="avatar">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-3.png" alt="User Avatar" />
</div>
</div>
<div>
<h6 class="text-base-content/90 text-base font-semibold">John Doe</h6>
<small class="text-base-content/50 text-sm font-normal">jhon@doe.com</small>
</div>
</li>
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
The basic dropdown menu featuring a slide-up animation.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-Slide" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu transition-[opacity,margin] duration-300 dropdown-open:opacity-100 hidden min-w-60 mt-2" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-Slide">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Use dropdown-open:{tw-utility-class}
modifier to introduce animation to your dropdown menu. The following example demonstrates a scaling animation.
<div class="w-full">
<div class="dropdown relative inline-flex [--strategy:absolute]">
<button id="dropdown-transform" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 dropdown-open:ease-in dropdown-open:scale-100 mt-0 hidden min-w-60 origin-top-left rtl:origin-top-right scale-0 transition duration-300 ease-out rtl:left-0" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-transform">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
</div>
Apply the dropdown-open:{tw-utility-class}
modifier to introduce animation to your dropdown menu sub container. Also add data-dropdown-transition
attribute for the sub-container.
The following example demonstrates a translate animation of content.
<div class="w-full">
<div class="dropdown relative inline-flex [--strategy:absolute]">
<button id="dropdown-transform" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60 rtl:left-0" role="menu" aria-orientation="vertical">
<ul class="dropdown-open:ease-in dropdown-open:translate-x-0 -translate-x-1 rtl:translate-x-1 transition duration-300 ease-out" aria-labelledby="dropdown-transform" data-dropdown-transition>
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
</div>
</div>
Add class .active
to set the active state.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-active" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-active">
<li><a class="dropdown-item active" href="#" aria-current="true">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Add class .disabled
to set the disabled state.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-disabled" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-disabled">
<li><a class="dropdown-item disabled" href="#" aria-disabled="true">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
The default trigger mode is click, you can change it to hover by adding [--trigger:hover]
with dropdown
.
<div class="dropdown relative inline-flex [--trigger:hover] rtl:[--placement:bottom-end]">
<button id="dropdown-hover" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-hover">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
The default dropdown menu with dividers.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-dividers" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dividers">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
<li><hr class="border-base-content/25 -mx-2 my-3" /></li>
<li><a class="dropdown-item" href="#">Pricing</a></li>
<li><hr class="border-base-content/25 -mx-2 my-3" /></li>
<li><a class="dropdown-item" href="#">Logout Out</a></li>
</ul>
</div>
The standard dropdown menu featuring icons.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-icons" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-icons">
<li>
<a class="dropdown-item" href="#">
<span class="icon-[tabler--bell] size-5"></span>
My Profile
</a>
</li>
<li>
<a class="dropdown-item" href="#">
<span class="icon-[tabler--garden-cart] size-5"></span>
Settings
</a>
</li>
<li>
<a class="dropdown-item" href="#">
<span class="icon-[tabler--cloud-download] size-5"></span>
Billing
</a>
</li>
<li>
<a class="dropdown-item" href="#">
<span class="icon-[tabler--users] size-5"></span>
FAQs
</a>
</li>
</ul>
</div>
The standard dropdown menu with shortcuts using keyboard
component.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-shortcuts" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-shortcuts">
<li>
<a class="dropdown-item justify-between" href="#">
Dashboard
<span class>
<kbd class="kbd kbd-sm">⌘</kbd>
+
<kbd class="kbd kbd-sm">i</kbd>
</span>
</a>
</li>
<li>
<a class="dropdown-item justify-between" href="#">
Settings
<span class>
<kbd class="kbd kbd-sm">⌘</kbd>
+
<kbd class="kbd kbd-sm">s</kbd>
</span>
</a>
</li>
<li>
<a class="dropdown-item justify-between" href="#">
Billing
<span class>
<kbd class="kbd kbd-sm">⌘</kbd>
+
<kbd class="kbd kbd-sm">d</kbd>
</span>
</a>
</li>
<li>
<a class="dropdown-item justify-between" href="#">
Sign out
<span class>
<kbd class="kbd kbd-sm">⌘</kbd>
+
<kbd class="kbd kbd-sm">l</kbd>
</span>
</a>
</li>
</ul>
</div>
Apply the vertical-scrollbar
class to create a scrollable area, and define the minimum height for this container.
Notification
Charles Franklin
Accepted your connectionMartian added moved Charts & Maps task to the done board.
Today 10:00 AMNew Message
You have new message from NatalieApplication has been approved 🚀
Your ABC project application has been approved.New message from Jane
Your have new message from JaneBarry Commented on App review task.
Today 8:32 AM<div class="dropdown relative inline-flex rtl:[--placement:bottom]">
<button id="dropdown-scrollable" type="button" class="dropdown-toggle" aria-label="Notification Button">
<div class="indicator">
<span class="indicator-item bg-error size-2.5 rounded-full"></span>
<span class="icon-[tabler--bell] text-base-content size-5"></span>
</div>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-scrollable">
<div class="dropdown-header justify-center">
<h6 class="text-base text-base-content/90">Notification</h6>
</div>
<div class="vertical-scrollbar rounded-scrollbar text-base-content/80 max-h-52 max-sm:max-w-72">
<div class="dropdown-item">
<div class="avatar away-bottom">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-1.png" alt="User Avatar" />
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="truncate text-base">Charles Franklin</h6>
<small class="text-base-content/50 truncate">Accepted your connection</small>
</div>
</div>
<div class="dropdown-item">
<div class="avatar">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-2.png" alt="User Avatar" />
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="!truncate text-base">Martian added moved Charts & Maps task to the done board.</h6>
<small class="text-base-content/50 truncate">Today 10:00 AM</small>
</div>
</div>
<div class="dropdown-item">
<div class="avatar online-bottom">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-8.png" alt="User Avatar" />
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="truncate text-base">New Message</h6>
<small class="text-base-content/50 truncate">You have new message from Natalie</small>
</div>
</div>
<div class="dropdown-item">
<div class="avatar placeholder">
<div class="bg-neutral text-neutral-content w-10 rounded-full p-2">
<span class="icon-[tabler--user] size-full"></span>
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="truncate text-base">Application has been approved 🚀</h6>
<small class="text-base-content/50 text-wrap">Your ABC project application has been approved.</small>
</div>
</div>
<div class="dropdown-item">
<div class="avatar">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-10.png" alt="User Avatar" />
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="truncate text-base">New message from Jane</h6>
<small class="text-base-content/50 text-wrap">Your have new message from Jane</small>
</div>
</div>
<div class="dropdown-item">
<div class="avatar">
<div class="w-10 rounded-full">
<img src="https://cdn.flyonui.com/fy-assets/avatar/avatar-3.png" alt="User Avatar" />
</div>
</div>
<div class="w-52 sm:w-60">
<h6 class="truncate text-base">Barry Commented on App review task.</h6>
<small class="text-base-content/50 truncate">Today 8:32 AM</small>
</div>
</div>
</div>
<a href="#" class="dropdown-footer justify-center gap-1">
<span class="icon-[tabler--eye] size-4"></span>
View all
</a>
</div>
</div>
With join
you can combine a dropdown and input into one unit.
<div class="join">
<input class="input join-item" placeholder="Email" />
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end] w-full">
<button id="dropdown-input" type="button" class="dropdown-toggle btn btn-primary join-item" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-input">
<li><a class="dropdown-item" href="#">Subscribe</a></li>
<li><a class="dropdown-item" href="#">Verify</a></li>
</ul>
</div>
</div>
Apply the Responsive modifier to adapt the dropdown position across different viewport sizes.
For instance, for below example the initial position is set to bottom-start, and it changes to right-start above the ‘sm’ breakpoint.
<div class="dropdown relative inline-flex [--placement:bottom-start] sm:[--placement:right-start]">
<button id="dropdown-sm" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" aria-labelledby="dropdown-sm">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
By default, clicking inside or outside the dropdown menu will close it. You can modify this behavior using the [--auto-close="true(DEFAULT) | inside | outside | false"]
option.
true
: The dropdown closes when clicked both inside and outside.inside
: Allow click inside dropdown mainly for input component.outside
: Allow click outside dropdown.false
: The dropdown only closes when the button is clicked.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]">
<button id="dropdown-outside" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
True (DEFAULT)
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-outside">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--auto-close:inside] rtl:[--placement:bottom-end]">
<button id="dropdown-transportation" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Inside
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<div class="dropdown-menu dropdown-open:opacity-100 hidden" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-transportation">
<div class="dropdown-item gap-4">
<input
id="dropdown-radio-car"
name="dropdown-item-radio-2"
type="radio"
class="radio radio-primary"
checked/>
<label for="dropdown-radio-car">
<span class="text-base-content/90 block text-sm font-semibold">Car</span>
</label>
</div>
<div class="dropdown-item gap-4">
<input id="dropdown-radio-bicycle" name="dropdown-item-radio-2" type="radio" class="radio radio-primary" />
<label for="dropdown-radio-bicycle">
<span class="text-base-content/90 block text-sm font-semibold">Bicycle</span>
</label>
</div>
</div>
</div>
<div class="dropdown relative inline-flex [--auto-close:outside] rtl:[--placement:bottom-end]">
<button id="dropdown-outside" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Outside
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-outside">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--auto-close:false] rtl:[--placement:bottom-end]">
<button id="dropdown-false" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
False
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-false">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
By default, the strategy
is set to ‘fixed’. To switch it to ‘absolute’, use the [--strategy:*]
option.
<div class="w-full">
<div class="dropdown relative inline-flex [--strategy:absolute]">
<button id="dropdown-strategy" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60 rtl:left-0" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-strategy">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
</div>
Use [--offset:*]
to set the number of pixels you want the dropdown menu to be offset from the trigger element.
<div class="dropdown relative inline-flex [--offset:30] rtl:[--placement:bottom-end]">
<button id="dropdown-offset" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-offset">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Use [--skidding:*]
to move up or down (or left and right) the dropdown menu along and relative to the trigger element.
<div class="dropdown relative inline-flex [--skidding:60] rtl:[--placement:bottom-end]">
<button id="dropdown-skidding" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-skidding">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
If you prefer to disable the automatic positioning of the dropdown-menu
.
<div class="dropdown relative inline-flex [--flip:false] rtl:[--placement:bottom-end]">
<button id="dropdown-flip" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-flip">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
By default the dropdown direction is bottom-start. To change it use [--placement:*]
. For centered use simple top
, bottom
, right
, left
direction.
Use [--placement:top | top-start | top-end]
class to trigger dropup menus above elements.
<div class="dropdown relative inline-flex [--placement:top-start]">
<button id="dropdown-dropup-start" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Top start
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropup-start">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:top] max-sm:[--placement:top-end]">
<button id="dropdown-dropup" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Top
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropup">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:top-end]">
<button id="dropdown-dropup-end" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Top end
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropup-end">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
Use [--placement:bottom | bottom-start(DEFAULT) | bottom-end]
class to trigger dropdown menus above elements.
<div class="dropdown relative inline-flex">
<button id="dropdown-bottom-start" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Bottom start
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-bottom-start">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:bottom] max-sm:[--placement:bottom-start]">
<buttom id="dropdown-bottom" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Bottom
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</buttom left>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-bottom">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:bottom-end]">
<button id="dropdown-bottom-start" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Bottom end
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-bottom-start">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
Use [--placement:right | right-start | right-end]
class to trigger dropright menus above elements.
<div class="flex flex-col gap-9">
<div class="dropdown relative inline-flex [--placement:right-start] max-sm:[--placement:bottom-start]">
<button id="dropdown-dropright-start" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Right start
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropright-start">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:right] max-sm:[--placement:bottom-start]">
<buttom id="dropdown-dropright" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Right
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</buttom>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropright">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:right-end] max-sm:[--placement:bottom-start]">
<button id="dropdown-dropright-end" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Right end
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropright-end">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
</div>
Use [--placement:left | left-start | left-end]
class to trigger dropleft menus above elements.
<div class="dropdown relative inline-flex [--placement:left-start] max-sm:[--placement:bottom-end]">
<button id="dropdown-dropleft-start" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Left start
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropleft-start">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:left] max-sm:[--placement:bottom-end]">
<buttom id="dropdown-dropleft" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Left
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</buttom>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropleft">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
<div class="dropdown relative inline-flex [--placement:left-end] max-sm:[--placement:bottom-end]">
<button id="dropdown-dropleft-end" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Left end
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-dropleft-end">
<li><a class="dropdown-item" href="#"> My Profile </a></li>
<li><a class="dropdown-item" href="#"> Settings </a></li>
<li><a class="dropdown-item" href="#"> Billing </a></li>
<li><a class="dropdown-item" href="#"> FAQs </a></li>
</ul>
</div>
COMMAND | DESCRIPTION |
---|---|
Enter | Activates the selected tab. |
A-Z a-z | Focuses first item that matches keyboard input. |
Home End | Focuses first/last non-disabled item. |
Esc | Closes any open Menus. |
Focuses previous/next non-disabled item. |
PARAMETERS | DESCRIPTION | OPTIONS | DEFAULT VALUE |
---|---|---|---|
data-dropdown-transition | A data attribute is used to specify the container that will undergo animation. | - | - |
[--placement:*] | Defines the menu’s position upon opening. | top, top-start, top-end, bottom, bottom-start, bottom-end, right, right-start, right-end, left, left-start, left-end | bottom-start |
[--auto-close:*] | Specifies the area where clicking is allowed. | inside, outside, false, true | true |
[--strategy:*] | Indicates the area that, when clicked, will trigger the menu to close. | fixed, absolute | fixed |
[--offset:*] | Adjusts the dropdown’s offset from the bottom or top. | number | 5 |
[--skidding:*] | Adjusts the dropdown’s skidding from the right or left. | number | 0 |
[--flip:*] | Changes the menu’s position to prevent overlapping with its reference element. | true, false | true |
[--trigger:*] | Event to trigger a dropdown | hover , click | click |
The HSDropdown
object is contained within the global window
object.
METHOD | DESCRIPTION |
---|---|
PUBLIC METHODS | |
open() | Opens the dropdown menu forcefully. |
close(isAnimated) | Closes the dropdown menu forcefully.
|
forceClearState() | Completely removes the dropdown. |
STATIC METHODS | |
HSDropdown.getInstance(target) | Retrieves the element associated with the target .
|
HSDropdown.open(target) | Forces the dropdown menu to open.
|
HSDropdown.close(target) | Forces the dropdown menu to close.
|
Below, is the demonstration on how to use the public methods. Apply the ID to the dropdown
component class. To test other methods, copy the following methods into your console and click the button.
<div class="flex gap-10 flex-wrap">
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end] --prevent-on-load-init" id="dropdown-method">
<button id="dropdown-method-usage" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-method-usage">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<button class="btn btn-primary" id="open-btn">Method</button>
</div>
<script>
window.addEventListener('load', function () {
const dropdown = new HSDropdown(document.querySelector('#dropdown-method'))
const openBtn = document.querySelector('#open-btn')
openBtn.addEventListener('click', () => {
dropdown.open()
})
})
</script>
Open item (public method).
// This method is used in above example.
const dropdown = new HSDropdown(document.querySelector('#dropdown-method'));
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
dropdown.open();
});
Open item (static method).
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
HSDropdown.open('#dropdown-method');
});
Open item (mixed).
const { element } = HSDropdown.getInstance('#dropdown-method', true);
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
element.open();
});
METHOD | DESCRIPTION |
---|---|
on:open | Triggered whenever a dropdown menu is opened. |
on:close | Triggered whenever a dropdown menu is closed. |
Below, is the demonstration on how to use the event. Apply the ID to the dropdown
component class. To test these event, copy the following event into your console and click the button.
<div class="dropdown relative inline-flex rtl:[--placement:bottom-end]" id="dropdown-event">
<button id="dropdown-event-usage" type="button" class="dropdown-toggle btn btn-primary" aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown">
Dropdown
<span class="icon-[tabler--chevron-down] dropdown-open:rotate-180 size-4"></span>
</button>
<ul class="dropdown-menu dropdown-open:opacity-100 hidden min-w-60" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-event-usage">
<li><a class="dropdown-item" href="#">My Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Billing</a></li>
<li><a class="dropdown-item" href="#">FAQs</a></li>
</ul>
</div>
<script>
window.addEventListener('load', function () {
const { element } = HSDropdown.getInstance('#dropdown-event', true)
element.on('open', instance => {
console.log('open')
})
element.on('close', instance => {
console.log('close')
})
})
</script>
Open any dropdown event example.
const { element } = HSDropdown.getInstance('#dropdown-event', true)
element.on('open', (instance) => {console.log("open")});
element.on('close', (instance) => {console.log("close")});