A responsive menu build for Vue.js
A renderless Vue component that will auto detect if menu items don't fit and moves them to a separate dropdown. Also known as the Priority+ pattern.
Demo 👈
👉Install
yarn add vue-responsive-menu
Register as a Vue component
; components: VueResponsiveMenu ;
:nav
prop
Pass your menu in the Responsive menu will expose 2 new arrays in the default prop, 1 normal menu & 1 with the excess items
<!-- Renderless component that exposes 2 arrays based on the array you pass in the nav prop. --> <!-- Default menu --> {{ item.name }} <!-- More menu with the items that didn't fit --> {{ menuItems.length === 0 ? '☰' : 'more ↓' }} {{ item.name }}
Props
Prop | Type | Default | Description |
---|---|---|---|
:nav | array<object> |
[] |
|
:maxCharacters | number or boolean |
false |
|
label | string |
'label' |
Key to read the menu item label. Only needed if you enable maxCharacters. |
offset | number |
0 |
Adds x amount of pixels to the total width of menu items. This causes menu items to be moved more quickly to the more dropdown |
Events
Name | Payload | Description |
---|---|---|
@menu-resized | number |
current width of menu |
@item-to-dropdown | object |
Item from nav prop |
@item-to-menu | object |
Item from nav prop |
@moreMenuItems | array |
Current array of more menu items |
@menuItems | array |
Current array of menu items |
Example with options
<!-- This will render max 35 characters counted from the name key in the nav array. In this case the first 5 menu items --> <!-- ... -->
Todo
- Make a public example site
- Create GIF in documentation
- Add documentation
- Write tests
- Setup CI
- Add contribution guidelines