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

Wrapping MenuItem or SubMenu wasn't possible anymore #115

Merged
merged 2 commits into from
May 22, 2017
Merged

Wrapping MenuItem or SubMenu wasn't possible anymore #115

merged 2 commits into from
May 22, 2017

Conversation

codeart1st
Copy link
Contributor

Sorry for all the PRs 😄
With my previous added implementation it wasn't possible anymore to wrap e.g. the MenuItem in an custom component like this:

export default MyCoolCustomMenuItemAction = () => (
  <MenuItem onClick={e => alert('fancy stuff')}>
    <CoolCustomIcon /><span>Menu Entry</span>
  </MenuItem>
)
<ContextMenu>
  <MyCoolCustomMenuItemAction />
</ContextMenu>

Now I implemented a simple recursive way to render and select the MenuItems/SubMenus.

@vkbansal
Copy link
Owner

Sorry for all the PRs 😄

No issues.

@codeart1st
Copy link
Contributor Author

Mh... the code works with elements like div, but not with react components. Need to debug it...

@codeart1st
Copy link
Contributor Author

codeart1st commented May 21, 2017

my example was quite bad.

export default MyCoolCustomMenuItemAction = () => (
  <MenuItem onClick={e => alert('fancy stuff')}>
    <CoolCustomIcon /><span>Menu Entry</span>
  </MenuItem>
)
<ContextMenu>
  <MyCoolCustomMenuItemAction />
</ContextMenu>

With this PR I iterate through props.children and the MyCoolCustomMenuItemAction has no children 😄

I haven't any ideas yet to achive the above example working

@codeart1st
Copy link
Contributor Author

import React from 'react'
import PropTypes from 'prop-types'
import { MenuItem } from 'react-contextmenu'
import FaPlus from 'react-icons/lib/fa/plus'

const AddMarkerAction = ({ children }) => (
  <div>{ children }</div>
)

AddMarkerAction.propTypes = {
  children: PropTypes.node
}

AddMarkerAction.defaultProps = {
  children: (
    <MenuItem>
      <FaPlus />
      <span>Hinweispunkt setzen</span>
    </MenuItem>
  )
}

export default AddMarkerAction

This works 👍

@vkbansal
Copy link
Owner

Can I merge this now?

@codeart1st
Copy link
Contributor Author

Yes, tested it in my local project. Works great.

@vkbansal vkbansal merged commit 716fb1f into vkbansal:master May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants