react-contexify icon indicating copy to clipboard operation
react-contexify copied to clipboard

Props not passed when Items inside intermediary component

Open rafaponieman opened this issue 4 years ago • 8 comments

Hi! While running similar code to the following, I find that, when Item is placed inside a fragment, or inside of another component that goes into Menu, the click event received by the handler is undefined, and the props aren't passed on.

<Menu>
  <Item onClick={onMenuItemClick}>Item 1</Item>
  {asd === dsa && (
    <>
      <Item onClick={onMenuItemClick}>Item 2</Item>
      <Item onClick={onMenuItemClick}>Item 3</Item>
    </>
  )}
</Menu>

rafaponieman avatar Dec 04 '19 02:12 rafaponieman

Happens to me to. Something broke in the latest versions - it used to works. It seems the when Item is created, for the inner items, props.propsFromTrigger isn't passed.

When investigating more, it may be due to cloneItem doing React.cloneElement to theitem - it does a shallow clone, and so the object propsFromTrigger isn't cloned.

edit: That's not it. I don't knoe the reason.

ymoran00 avatar Jan 12 '20 14:01 ymoran00

I could be wrong, but I believe it's this line where the children are cloned.

From react docs

If children is a Fragment it will be treated as a single child and not traversed.

If that is the issue, possible solution with react-is lib and editing this util fn. https://stackoverflow.com/questions/49012718/check-if-a-child-is-react-fragment

sbrichardson avatar Dec 24 '20 10:12 sbrichardson

Hey @sbrichardson, thanks a lot for sharing those details. I'll work on a fix

fkhadra avatar Dec 24 '20 10:12 fkhadra

I have same the problem. Any progress?

enomado avatar Jun 09 '21 15:06 enomado

Also running into this issue. Anyone know the last version that this worked on?

djkingCanada avatar Aug 27 '21 18:08 djkingCanada

Any fix on this?

Also running into this issue.

jorgerojas26 avatar Apr 03 '22 16:04 jorgerojas26

Facing the same problem in 2023…

javascripet avatar Jul 12 '23 22:07 javascripet

Hello I am trying to access pops in the submenu click then getting undefined. is this issue is fixed?

LaxmanPache123 avatar Dec 08 '23 11:12 LaxmanPache123