import React from 'react' ; import Menu from '@material-ui/core/Menu' ; import { useBaseMenuContext } from './BaseMenuContext' ; const BaseMenuList = ( { children } ) => { const { anchorEl , closeMenu } = useBaseMenuContext ( ) ; if ( ! children ) { return null ; } return ( < Menu id = "base-menu" anchorEl = { anchorEl } keepMounted open = { Boolean ( anchorEl ) } onClose = { closeMenu } > { React . Children . map ( children , ( child ) => { if ( ! React . isValidElement ( child ) ) { throw new Error ( 'BaseMenuList children are not valid' ) ; } const onClick = ( e ) => { child ?. props . onClick ?. ( e ) ; closeMenu ?. ( e , 'backdropClick' ) ; } ; return React . cloneElement ( child , { onClick } ) ; } ) } < /Menu>); } ; export default BaseMenuList ;