Skip to main content

Menu

Usage

import { useState } from 'react';
import Menu from '@mavvy/m3-ui/Menu';
import Button from '@mavvy/m3-ui/Button';
import Text from '@mavvy/m3-ui/Text';

function Example() {
const [value, setValue] = useState('');
const items = [
{
text: 'Home',
value: 'home',
active: true,
},
{
text: 'Premium',
value: 'premium',
disabled: true,
},
{
text: 'Profile',
value: 'profile',
},
{
isDivider: true,
},
{
text: 'Logout',
value: 'logout',
leadingIcon: 'logout',
},
];
const handleChange = (v) => {
setValue(v);
};

return (
<div className="flex flex-col justify-center">
<Text>selected value: {value}</Text>
<Menu items={items} onChange={handleChange}>
<Button variant="filled" color="primary">
Open
</Button>
</Menu>
</div>
);
}

selected value:

Props

proptypedescription
itemsMenuItemProps[]required. menu items array
onChange(value:string, index: number) => voidrequired. on change handler
menuListClassNamestringclassName to be applied on the menu list container
itemClassNamestringclassName to be applied on each menu item
positiontop-left|top-right|bottom-left|bottom-rightposition of the menu list
childrenReact.ReactNodereact children
disableRemoveOverflowbooleandefault behaviour is to add an overflow class to the body, set if to true to disable it
proptypedescription
textstringmenu text to display on the list
valuestringmenu item value to pass on the change handler
trailingIconstringicon name to display as a trailing icon
trailingTextstringtrailing text
isDividerbooleanrender as a divider
disabledbooleanif true, will set the item as disabled
actionbooleanif true, will set the state as active