Menus
Versatile navigation lists for organizing and presenting action options, navigation links, and interactive choices. Perfect for sidebars, dropdowns, and contextual menus with support for horizontal/vertical layouts, nesting, icons, and various interaction states.
Vertical menus no longer have a default width. Use w-full or other width
classes if you want to control the width.
Basic Menu
Menus typically contain a list of links or buttons that users can click. The styling is very minimal, just adding a hover effect.
= daisy_menu(css: "w-56") do |menu|
- # Menu Item Group with a title keyword argument
- menu.with_item(title: "Group 1") do
= link_to "Item 1 - 1", "#"
- # Menu Item Group with a title as the first positional argument
- menu.with_item("Group 2") do
= link_to "Item 2 - 1", "#"
- menu.with_item do
= link_to "Item 2 - 2", "#"
Horizontal Menu
Menus can be displayed horizontally by adding the .menu-horizontal class
to the menu. They can also have icons, disabled / active items, and many
other options.
Use menu-active, menu-focus, and menu-disabled classes to style menu
items in different states.
We can't actually disable the link since the HTML spec does not allow
that (instead you should generally just make it text). However, we can
disable the link with CSS and use .pointer-events-none to ensure it
cannot be clicked. You may also want to add tabindex: -1 to your link
to ensure it cannot be focused with the keyboard.
= daisy_menu(css: "menu-horizontal") do |menu|
- menu.with_item do
= link_to "Item 1", "#"
- menu.with_item(disabled: true) do
= link_to "Item 2", "#", tabindex: -1
- menu.with_item do
= link_to "Item 3", "#", class: "menu-active"
Nested Menus
Menus can also contain nested menus. This is useful for organizing a large number of options.
- icon_options = { css: "size-4 mr-1 text-slate-600" }
= daisy_menu(css: "w-56 bg-base-100 border border-base-300 rounded-lg shadow-md") do |menu|
- menu.with_item do
= link_to "#" do
= loco_icon("home/mini", **icon_options)
Home
- menu.with_item do
= link_to "#" do
= loco_icon("bell-alert/mini", **icon_options)
Notifications
- menu.with_item(title: "Parent") do
= daisy_menu(css: "w-full") do |menu|
- menu.with_item do
= link_to "Child 1", "#"
- menu.with_item do
= link_to "Child 2", "#"
- menu.with_item do
- icon_options[:css] += " text-yellow-500!"
= link_to "#" do
Child 3
= loco_icon("bolt/mini", **icon_options)