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

Allow a onClick prop so we can stop propagation

Open benjamindulau opened this issue 8 years ago • 3 comments

I have a use case where the Toggle button is on a list of items which are selectable by a mouse click. So switching the toggle state also propagates a click event and my list item selection gets toggled too and I don't want that :)

All we need to prevent this is to be able to pass an onClick handler as a prop to the Toggle component so we can just do a event.stopPropagation and thus prevent further event handlers to be executed (in my case the container's click event which toggles the item selected state).

For now I need to check the target manually in the parent's click handler.

Cheers

benjamindulau avatar Dec 19 '16 17:12 benjamindulau

By the way, adding a wrapper around the Toggle and stopping propagation there also works but I like my clean markups ;-)

benjamindulau avatar Dec 19 '16 17:12 benjamindulau

It would be a great addition !

Darkilen avatar Nov 06 '18 11:11 Darkilen

I'm happy to take a stab at an implementation of this. Adding an actual onClick prop might be confusing, though, since we'd need to explain that onClick is not recommended for use to obtain the status of the toggle.

Perhaps we should add a prop for stopPropagation instead, which would instrument the onClick handler internally.

I could write it for either case, but I'd be curious what @aaronshaf thinks.

curtvict avatar Sep 06 '22 21:09 curtvict