Search documentation v0.8.1

Dropdown Navigation

Display navigation options with dropdown menus

Source ↗️ Report Issue ↗️

Use the DropdownNavigation component to display a navigation menu with optional dropdown menus. They’re space efficient and can be used to organize menus with subcategories.

Preview
Unlock code
How to use the DropdownNavigation component in Astro
---
const dropdownNavigationMenuItems = [
{ name: 'Home', url: '/' },
{
name: 'Posts',
children: [
{ name: 'Getting Started', url: '#' },
{ name: 'Installation', url: '#' },
{ name: 'Configuration', url: '#' }
]
},
{ ... }
]
---
<DropdownNavigation
logo={{ html: '<svg ... />' }}
items={dropdownNavigationMenuItems}
/>

To use the DropdownNavigation component, you need to pass an array of navigation objects to the items prop. Each object can have the following properties:

Alongside the menu items, you can also display a logo by setting the logo prop. In the above example, the logo is set to an SVG string. However, you can also specify an external image by setting the following properties for the logo object:

CSS

By default, the DropdownNavigation component is set to sticky positioning, meaning it’ll follow the viewport on scroll. You can disable this in your dropdown-navigation.module.scss file by setting the $sticky variable at the top of the file to false:

Unlock code
How to disable sticky positioning in your component's CSS
$sticky: false;

There’s also an $expandedMaxHeight variable in the module CSS that you can use to customize the speed of the dropdown animation on mobile. Set this to a height greater than the height of your menu items combined.

API

Unlock code
Component API reference
type DropdownNavigationProps = {
items: {
name: string
url?: string
children?: {
name: string
url: string
}[]
}[]
logo?: {
url?: string
alt?: string
width?: number
height?: number
html?: string
}
className?: string
}
PropPurpose
items Sets the navigation links.
items.name Sets the name of the navigation link.
items.url Sets a url for the navigation link.
items.children Sets the submenu items of the navigation element, turning it into a dropdown menu.
items.children.name Sets the name of the submenu item.
items.children.url Sets the url of the submenu item.
logo Specifies a logo for the menu.
logo.url Sets the path for the logo.
logo.alt Sets an alternate text for the logo.
logo.width Sets the width of the logo.
logo.height Sets the height of the logo.
logo.html Use for directly injecting SVG logos into the markup.
className Pass additional CSS classes for the dropdown menu.

Request improvement for this page