Directory
- Welcome
Menu Component
The Menu component creates interactive selection interfaces with smooth transitions and accessibility features built-in. Perfect for navigation menus, tab interfaces, and content switching scenarios.
Key Features
-
State Management: Automatic handling of selection states
-
Event Handling: Built-in change events and callbacks
-
Accessibility: ARIA support and keyboard navigation
-
Customizable: Flexible styling and configuration options
Basic Usage
Create a simple menu with a list of options:
<Menu name="theme" items={['Light', 'Dark', 'System']} defaultItem="System"/>
Working with Menu Items
The Menu component includes a MenuItem
component for managing content visibility:
Product Details
View detailed information about the product.
Settings Panel
Configure your preferences and options.
<Menu name="tabs" items={['Details', 'Settings']} defaultItem="Details" />
<MenuItem name="tabs" itemName="Details"> <h3>Product Details</h3> <p>View detailed information about the product.</p></MenuItem>
<MenuItem name="tabs" itemName="Settings"> <h3>Settings Panel</h3> <p>Configure your preferences and options.</p></MenuItem>
Custom Event Listeners
The Menu component emits a menu-change
event when selection changes:
Waiting for events to be emitted… (Click on the menu to see the events)
// Listen for menu changesconst menu = document.querySelector('menu-wrapper');menu.addEventListener('menu-change', (event) => { const { menuName, itemName } = event.detail; console.log(`Menu: ${menuName}, Selected: ${itemName}`);});
Component API
Menu Props
Prop | Type | Default | Description |
---|---|---|---|
name | string | - | Unique identifier for the menu |
items | string[] | - | Array of menu items to display |
defaultItem | string | First item | Initially selected item |
buttonProps | ButtonProps | - | Props passed to button elements |
variant | default | minimal | pills | underline | segments | default | Variant of the menu |
orientation | horizontal | vertical | horizontal | Orientation of the menu |
fullWidth | boolean | false | Full width of the menu |
MenuItem Props
Prop | Type | Default | Description |
---|---|---|---|
name | string | - | Menu name this item belongs to |
itemName | string | - | Unique identifier for this item |
Variants
The Menu component comes with several built-in variants to suit different design needs:
Default
A classic menu with subtle shadows and borders:
Minimal
Clean and simple with bordered items:
Pills
Modern pill-shaped buttons with a frosted glass effect:
Underline
Elegant underlined navigation style:
Segments
Segmented control style with raised active state:
Sizes
Each variant supports multiple sizes via the buttonProps
prop:
Small
Medium
Default
Large
Extra Large
Orientation
Menus can be displayed horizontally or vertically:
Horizontal (Default)
Vertical
Full Width
Menus can expand to fill their container:
Regular Width
Full Width
Best Practices
-
Naming
- Use clear, descriptive menu names
- Keep item labels concise
- Ensure unique identifiers
-
Content Organization
- Group related items together
- Limit number of options
- Maintain consistent structure
Limited Time Launch Sale
Create intuitive navigation interfaces with our Menu component. Get started with our AstroJS starter template today!
GET 60% OFF!