Added ability to change event propagation mode from default "bubble" to "capture" #95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had a scenario where the tooltip needed to be triggered on click. However, the trigger element is contained within a parent component that needed to handle the trigger click event as well. Unfortunately, the tooltip checkStatus method stopped click propagation in order to add a handler for outside click events that will close the tooltip.
I tried using a custom event to activate the tooltip on trigger click. This almost worked as the click event was propagating but unfortunately the event was bubbling after the checkStatus outside handler was registered, so the tooltip was being hidden immediately.
The change I ultimately ended up making was to introduce a new prop to set the propagation mode to capture instead of bubble. This effectively disableds the e.stopPropagation call in checkStatus and changes the outside click handler to "capture" instead of "bubble", which allows the parent click event to be handled first and then displays the tooltip. And outside click events still close the tooltip.
I was wary that changing the default bubble behavior might have unintended consequences for other people using this component, so the default event propagation mode will always be "bubble". But by setting the "eventPropagationMode" prop to "capture", you can change the default behavior.