Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 0ed300a

Browse files
committed
add renderTag prop for custom wrapper
1 parent 4853220 commit 0ed300a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ Type: React Component
238238

239239
The `Menu` component that needs to be updated depending on the current selection. The component will receive object from `monitor.getItem()` in its props with `item` as key. All the other props will be simply passed through.
240240

241+
## Customization
242+
The higher order component created using `ContextMenuLayer` can accept the following props.
243+
244+
**renderTag**
245+
246+
Type: React Element (optional)
247+
248+
The element inside which the Component must be wrapped. By default `div` is used. But this prop can used to customize it.
249+
241250
## Credits
242251
This project is based on the ideas from [react-dnd](https://github.com/gaearon/react-dnd) by [Dan Abramov](https://github.com/gaearon).
243252

src/contextmenu-layer.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import _isObject from "lodash.isobject";
66

77
import store from "./redux/store";
88

9-
let { Component } = React;
10-
119
export default function(identifier, configure) {
1210
return function(Component) {
1311
const displayName = Component.displayName
@@ -33,6 +31,11 @@ export default function(identifier, configure) {
3331

3432
return React.createClass({
3533
displayName: `${displayName}ContextMenuLayer`,
34+
getDefaultProps() {
35+
return {
36+
renderTag: "div"
37+
};
38+
},
3639
handleContextClick(event) {
3740
let currentItem = typeof configure === "function"
3841
? configure(this.props)
@@ -57,12 +60,10 @@ export default function(identifier, configure) {
5760
});
5861
},
5962
render() {
60-
return (
61-
<div className="react-context-menu-wrapper"
62-
onContextMenu={this.handleContextClick}>
63-
<Component {...this.props}/>
64-
</div>
65-
);
63+
return React.createElement(this.props.renderTag, {
64+
className: "react-context-menu-wrapper",
65+
onContextMenu: this.handleContextClick
66+
}, React.createElement(Component, this.props));
6667
}
6768
});
6869
};

0 commit comments

Comments
 (0)