Gathering detailed insights and metrics for @material/react-menu-surface
Gathering detailed insights and metrics for @material/react-menu-surface
Gathering detailed insights and metrics for @material/react-menu-surface
Gathering detailed insights and metrics for @material/react-menu-surface
Material Components for React (MDC React)
npm install @material/react-menu-surface
Typescript
Module System
Node Version
NPM Version
TypeScript (92.35%)
CSS (4.36%)
JavaScript (2.51%)
Shell (0.39%)
Dockerfile (0.26%)
HTML (0.13%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,023 Stars
471 Commits
231 Forks
62 Watchers
6 Branches
64 Contributors
Updated on May 29, 2025
Latest Version
0.15.0
Package Id
@material/react-menu-surface@0.15.0
Unpacked Size
174.15 kB
Size
44.10 kB
File Count
15
NPM Version
6.8.0
Node Version
10.13.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
A React version of an MDC Menu Surface.
npm install @material/react-menu-surface
with Sass:
1import '@material/react-menu-surface/index.scss';
with CSS:
1import '@material/react-menu-surface/dist/menu-surface.css';
React Menu Surface accepts one child element. Please see the below example if you need to anchor the menu surface to a specific element. In this case, we wrapper <button>
and <MenuSurface>
element within the anchor, and give the mdc-menu-surface--anchor
class to the element. You can specify a corner for the menu surface to appear from, otherwise it defaults to top-left. For a list of different anchor corner values, please see the MDC Web Menu Surface constants.ts file.
NOTE:
<MenuSurface>
also has anonClose
callback method prop, which is called when the menu closes. Use this as an opportunity to update your application's state.
1import React from 'react'; 2import MenuSurface, {Corner} from '@material/react-menu-surface'; 3import Button from '@material/react-button'; 4 5class MyApp extends React.Component { 6 state = { 7 open: false, 8 anchorElement: null, 9 }; 10 11 setAnchorElement = (element) => { 12 if (this.state.anchorElement) { 13 return; 14 } 15 this.setState({anchorElement: element}); 16 } 17 18 render() { 19 return ( 20 <div 21 className='mdc-menu-surface--anchor' 22 ref={this.setAnchorElement} 23 > 24 <Button raised onClick={() => this.setState({open: true})}>Open Menu</Button> 25 26 <MenuSurface 27 open={this.state.open} 28 anchorCorner={Corner.BOTTOM_LEFT} 29 onClose={() => this.setState({open: false})} 30 anchorElement={this.state.anchorElement} 31 > 32 <img 33 style={{maxWidth: '20vw', maxHeight: '20vh'}} 34 src='http://images.my.photo.url' /> 35 </MenuSurface> 36 </div> 37 ); 38 } 39}
You may want to anchor your menu surface to x, y coordinates. One example being a right-click contextmenu. Instead of passing an anchorElement
you need to pass coordinates
.
1import React from 'react'; 2import MenuSurface from '@material/react-menu-surface'; 3 4class MyApp extends React.Component { 5 state = { 6 open: false, 7 coordinates: null, 8 }; 9 10 componentDidMount() { 11 this.rightClickCallback_ = (evt) => { 12 this.setState({ 13 open: true, 14 coordinates: {x: evt.clientX, y: evt.clientY}, 15 }); 16 evt.preventDefault(); 17 }; 18 19 window.addEventListener('contextmenu', this.rightClickCallback_); 20 } 21 22 componentWillUnmount() { 23 window.removeEventListener('contextmenu', this.rightClickCallback_); 24 } 25 26 render() { 27 return ( 28 <div className='my-app'> 29 <h1>Menu Surface</h1> 30 31 <MenuSurface 32 open={this.state.open} 33 onClose={() => this.setState({open: false, coordinates: null})} 34 coordinates={this.state.coordinates} 35 > 36 <img 37 style={{maxWidth: '20vw', maxHeight: '20vh'}} 38 src='http://images.my.photo.url' /> 39 </MenuSurface> 40 </div> 41 ); 42 } 43}
NOTE: The React menu surface component is always hoisted to the body. This is one place the component differs from MDC Web's version, which gives the option of hoisting/not hoisting. Always hoisting the menu surface to the body allows fixes a few issues, and simplifies the component API.
Prop Name | Type | Description |
---|---|---|
className | String | Classes to be applied to the root element. |
anchorCorner | Corner | Sets the corner that the menu surface will be anchored to. See MDC Web constants.js. |
anchorElement | Element | Sets the anchor element used as an anchor for menu-surface positioning logic. Should contain class .mdc-menu-surface--anchor . |
anchorMargin | Object* | Sets the distance from the anchor point that the menu surface should be shown. |
coordinates | {x: Number, y: Number} | Sets the anchor coordinates when menu surface does not use anchorElement. |
open | Boolean | Changing value will trigger open/close of the menu surface. |
quickOpen | Boolean | Disables the open/close animation of the menu surface, which makes the open/close instant. |
fixed | Boolean | Sets the menu surface to fixed positioning. |
onClose | Function | Callback triggered after menu surface closes. |
- | AnchorMargin takes the form of {top: Number, bottom: Number , left: Number , right : Number}
Sass mixins may be available to customize various aspects of the components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.
Please see our Best Practices doc when importing or using icon fonts.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 28/30 approved changesets -- score normalized to 9
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
186 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More