pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.39k stars 180 forks source link

Question about using react fragments #295

Closed Specy closed 3 years ago

Specy commented 3 years ago

I have a component which calls another component that returns an interactive container, I've added a click listener to this container and it seems to work, but then I had to add another element other than this container so I used a fragment (<>) to group the two components, at that point the click event stopped working, so the question being, since we have to specify when an element is interactive and if their children are interactive, does the shard also count in this? Is this the reason why the click events don't trigger?

Also, why is a container with set width and height not clickable if its children don't occupy the area?

inlet commented 3 years ago

Can you create an example in codepen or codesandbox?

Specy commented 3 years ago

https://codesandbox.io/s/fervent-lichterman-5x8vv?file=/src/App.js

top square has element that fills X and registers clicks, the second which has no children filling x, doesn't register any clicks

inlet commented 3 years ago

PIXI's interaction manager calculates the bounding rects of its children to register click events. This is the expected behaviour.

Here's the demo in plain PIXI: https://www.pixiplayground.com/#/edit/xTTZGTcLufmLcSdMkARgM