React 上下文目录(Contextmenu)
made with
React
简介及使用教程
React 上下文目录(Contextmenu)是一个React中的上下文目录(Contextmenu)组件,带可访问性支持。
安装
Npm
npm i react-contextmenu
Yarn
yarn add react-contextmenu
使用
import React from "react";
import ReactDOM from "react-dom";
import { ContextMenu, MenuItem, ContextMenuTrigger } from "react-contextmenu";
function handleClick(e, data) {
console.log(data.foo);
}
function MyApp() {
return (
<div>
{/* NOTICE: id must be unique between EVERY <ContextMenuTrigger> and <ContextMenu> pair */}
{/* NOTICE: inside the pair, <ContextMenuTrigger> and <ContextMenu> must have the same id */}
<ContextMenuTrigger id="same_unique_identifier">
<div className="well">Right click to see the menu</div>
</ContextMenuTrigger>
<ContextMenu id="same_unique_identifier">
<MenuItem data={{foo: 'bar'}} onClick={this.handleClick}>
ContextMenu Item 1
</MenuItem>
<MenuItem data={{foo: 'bar'}} onClick={this.handleClick}>
ContextMenu Item 2
</MenuItem>
<MenuItem divider />
<MenuItem data={{foo: 'bar'}} onClick={this.handleClick}>
ContextMenu Item 3
</MenuItem>
</ContextMenu>
</div>
);
}
ReactDOM.render(<MyApp myProp={12}/>, document.getElementById("main"));
API:API docs
作者
Vivek Kumar Bansal
@_vkbansal相关项目