react-selectable-fast icon indicating copy to clipboard operation
react-selectable-fast copied to clipboard

Feature Request: Stop click event propagation

Open zachgibson opened this issue 5 years ago • 5 comments

My use-case is a bit different than your example. I’m rendering pseudo UI, e.g. a button that is comprised of a rectangle and text on top of it. Using this pseudo button as an example, when I click the text, the event propagates and both the text and the rectangle are selected. I need to be able to select items individually regardless if they’re on top of other elements.

react-selectable-example

@valerybugakov What are your thoughts on this? I’m happy to create a PR if you could point me in the right direction of where this propagation would need to stop. And I’m assuming this would need to be an optional prop as it’d probably break existing behavior just adding it.

zachgibson avatar Nov 28 '18 23:11 zachgibson

Hey @zachgibson, it happens because click event is handled the same way as item selection via the select lasso. We collect the coordinates of the click event, then select all selectable items intersecting with these coordinates.

The way to fix it from the top of my head is to handle click separately. If we see that e.target is a selectable item then we can just select it instead of calling this.selectItems. It should be done in SelectableGroup method handleClick.

valerybugakov avatar Dec 23 '18 13:12 valerybugakov

Hey I have a similar question, I guess. The component I use as a createSelectable needs to react to a separate onClick event - I always want to know which component in the grid was clicked on last. But when I add an onClick handler the clicks are being ignored. Do you have any suggestion for me on how to solve it?

I did not understand what you mean by

It should be done in SelectableGroup method handleClick.

  • is this a function already implemented on SelectableGroup ? If so, I could not find it in the docs.

Thanks a lot in advance, I really love this package! :)

sergejostranow avatar Aug 08 '19 07:08 sergejostranow

Hey I have a similar question, I guess. The component I use as a createSelectable needs to react to a separate onClick event - I always want to know which component in the grid was clicked on last. But when I add an onClick handler the clicks are being ignored. Do you have any suggestion for me on how to solve it?

I did not understand what you mean by

It should be done in SelectableGroup method handleClick.

  • is this a function already implemented on SelectableGroup ? If so, I could not find it in the docs.

Thanks a lot in advance, I really love this package! :)

I have the same issue. Did you find anything? :)

vickyvishal avatar Aug 03 '20 21:08 vickyvishal

Okay, the only workaround is to move the component with the separate onClick outside the <SelectableGroup /> and place it using the properties selectedItems[i].bounds via css

vickyvishal avatar Aug 04 '20 10:08 vickyvishal

Hey @zachgibson, it happens because click event is handled the same way as item selection via the select lasso. We collect the coordinates of the click event, then select all selectable items intersecting with these coordinates.

The way to fix it from the top of my head is to handle click separately. If we see that e.target is a selectable item then we can just select it instead of calling this.selectItems. It should be done in SelectableGroup method handleClick.

I don't understand what to do.Can you be more specific or give an example? thank you

linxianxi avatar Dec 23 '21 07:12 linxianxi