fix(select): click handlers on slotted content fire #28839
Merged
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.
Issue number: resolves #28818
What is the current behavior?
Select has logic in place to prevent the overlay from opening when clicking the slotted content. As part of this, we need to deal with the
<label>
element dispatching another click that then bubbles up and causes the overlay to open when clicking the slotted content. We currently deal with this by callingpreventDefault
which prevents this extra event from being dispatched only when clicking the slotted content.We also call
stopPropagation
. This code is not necessary, and in most cases should not have any adverse effects on developer applications. However, this does impact React applications due to how React handles events. When a developer placesonClick
on a slotted element, a native "click" listener is not immediately applied to that element. Instead, React adds a native "click" listener to the root element of an application. When that listener's callback fires, React will dispatch a synthetic click event on the slotted element. Since we are callingstopPropagation
, the click event never bubbles up to this root node's listener. As a result, the synthetic event is never dispatched on the slotted element, and the developedonClick
callback never fires.What is the new behavior?
event.preventDefault
is sufficient to prevent the label from dispatching another click (thereby causing the select overlay to open) when clicking the slotted content.Does this introduce a breaking change?
Other information
Dev build:
7.6.5-dev.11705430252.1023daf3