<Stateinitial={0}>{([open, setOpen])=>(<ButtonGroup>{[['xs','Extra Small'],['s','Small'],['m','Medium'],['l','Large']].map((item, index)=>(<ActionMenukey={index}trigger={<Buttonselected={open === index}onClick={()=>setOpen(open !== index ? index :null)}>{item[1]}</Button>}open={open === index}portal={false}width={item[0]}><ActionMenu.ItemonClick={()=>setOpen(false)}>Item one</ActionMenu.Item><ActionMenu.ItemonClick={()=>setOpen(false)}>Item two</ActionMenu.Item></ActionMenu>))}</ButtonGroup>)}</State>
Overflow Handling
<ActionMenuopenportal={false}><ActionMenu.Item>Item One</ActionMenu.Item><ActionMenu.Item>Item long enough to wrap around to a second line</ActionMenu.Item><ActionMenu.Itemicon="phone">Item with Icon long enough to wrap around to a second line</ActionMenu.Item></ActionMenu>
Best Practices
The Action Menu component should:
Be easily discoverable. Action menus or right-click menus are often hardly discoverable. Especially in cases where there is no visual indication or a button to reveal the menu.
Have menu button placed to the right side of the affected item.
Present main actions before menu button, but secondary actions should be placed in an action menu itself.
For data entry in a Form, use the Select over the Action Menu.
Content Guidelines
Button name should describe the items in the menu
Users should be able to use the button name to predict what the options in the menu will apply to.
Action menu buttons should follow the content guidelines for buttons.
Do
Don't
Clearly name each item
Each item in the menu should be clearly named. Users should be able to predict what will happen when they click.
Each item should always start with a strong verb to describe the action. Add a noun to provide more context on what will be affected in cases where the verb alone isn’t clear enough. Format: [Verb] + [noun].
Use sentence case (capitalize only the first word and proper nouns) and avoid unnecessary words and articles such as the, an, or a.
Book job
View invoice
Rename file
Do
Book
View an invoice
File name changes
Don't
Item names should match destination
Menu item names should be the same as the destination they take the user to.
“Add existing location” menu item opens a drawer with header “Add existing location”.
Do
“Add existing location” menu item opens a drawer with header “Existing locations”.
Don't
Code
Handling click outside
Be careful with onClickOutside prop, especially when ActionMenu.Item are being used to open overlays, like Modal, Dialog, etc.
In this case ActionMenu needed to be closed explicitly before overlay to be opened. Check the example below:
<Stateinitial={{menuOpen:false,closeMenuOnItemClick:true,modalOpen:false,drawerOpen:false,dialogOpen:false,takeoverOpen:false}}>{([state, setState])=>{constonClickOutside=()=>{console.log('onClickOutside()'); state.menuOpen&&setState(prev=>({...prev,menuOpen:false}));}constMenuTrigger=(<ButtononClick={()=>setState(prev=>({...prev,menuOpen:!prev.menuOpen}))}> Menu <Iconname="more_vert"size="24"className="m-l-half m-r--1"/></Button>);const overlays =[{name:'Modal',fn:()=>setState(prev=>({...prev,modalOpen:!prev.modalOpen}))},{name:'Drawer',fn:()=>setState(prev=>({...prev,drawerOpen:!prev.drawerOpen}))},{name:'Dialog',fn:()=>setState(prev=>({...prev,dialogOpen:!prev.dialogOpen}))},];return(<div><ToggleSwitchlabel="Close Menu on Item click"checked={state.closeMenuOnItemClick}onChange={()=>setState(prev=>({...prev,closeMenuOnItemClick:!state.closeMenuOnItemClick}))}/><br/><br/><ActionMenusharp={false}width='s'direction='br'open={state.menuOpen}trigger={MenuTrigger}onClickOutside={onClickOutside}portal={false}>{overlays.map((i, ix)=>(<ActionMenu.Itemkey={ix}onClick={()=>{ state.closeMenuOnItemClick&&setState(prev=>({...prev,menuOpen:false})); i.fn();}}> Open {i.name}</ActionMenu.Item>))}</ActionMenu><Modaltitle="Modal"open={state.modalOpen}closableonClose={()=> overlays[0].fn()}> Modal Content</Modal><Drawerheader="Drawer"backdropopen={state.drawerOpen}onClose={()=> overlays[1].fn()}footer={<ButtononClick={overlays[1].fn}>Close Drawer</Button>}> Drawer Content</Drawer><Dialogtitle="Dialog"open={state.dialogOpen}onClose={()=> overlays[2].fn()}onPrimaryActionClick={overlays[2].fn}primaryActionName="Close Dialog"> Dialog Content</Dialog></div>)}}</State>