-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs][Menus] Adding an example for Grouped Menu
- Loading branch information
1 parent
c2335e6
commit ac18cfc
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/material/Button'; | ||
import ListSubheader from '@mui/material/ListSubheader'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import MenuList from '@mui/material/MenuList'; | ||
|
||
export default function GroupedMenu() { | ||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
const open = Boolean(anchorEl); | ||
const handleClick = (event) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Button | ||
id="basic-button" | ||
aria-controls={open ? 'grouped-menu' : undefined} | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={handleClick} | ||
> | ||
Dashboard | ||
</Button> | ||
<Menu | ||
id="grouped-menu" | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
MenuListProps={{ | ||
'aria-labelledby': 'basic-button', | ||
}} | ||
> | ||
<MenuList role="group"> | ||
<ListSubheader>Category 1</ListSubheader> | ||
<MenuItem onClick={handleClose}>Option 1</MenuItem> | ||
<MenuItem onClick={handleClose}>Option 2</MenuItem> | ||
<ListSubheader>Category 2</ListSubheader> | ||
<MenuItem onClick={handleClose}>Option 3</MenuItem> | ||
<MenuItem onClick={handleClose}>Option 4</MenuItem> | ||
</MenuList> | ||
</Menu> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
import Button from '@mui/material/Button'; | ||
import ListSubheader from '@mui/material/ListSubheader'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import MenuList from '@mui/material/MenuList'; | ||
|
||
export default function GroupedMenu() { | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
const open = Boolean(anchorEl); | ||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Button | ||
id="basic-button" | ||
aria-controls={open ? 'grouped-menu' : undefined} | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={handleClick} | ||
> | ||
Dashboard | ||
</Button> | ||
<Menu | ||
id="grouped-menu" | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
MenuListProps={{ | ||
'aria-labelledby': 'basic-button', | ||
}} | ||
> | ||
<MenuList role="group"> | ||
<ListSubheader>Category 1</ListSubheader> | ||
<MenuItem onClick={handleClose}>Option 1</MenuItem> | ||
<MenuItem onClick={handleClose}>Option 2</MenuItem> | ||
<ListSubheader>Category 2</ListSubheader> | ||
<MenuItem onClick={handleClose}>Option 3</MenuItem> | ||
<MenuItem onClick={handleClose}>Option 4</MenuItem> | ||
</MenuList> | ||
</Menu> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters