You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @corysmc thanks for reporting this issue! I can reproduce it with both ion-checkbox and ion-radio. It happens where we have a shadow DOM web component with the modern form control syntax and a label + input.
The label is the click target. When a label is associated with an input, it will trigger a click on the inner input, which propagates the additional click event.
I discussed this with the team, and we have determined this is not a bug in Ionic.
This behavior is happening because the click event is being retargeted as it moves from the Shadow DOM to the Light DOM. In the case of ion-checkbox, clicking the checkbox dispatches a click on the <label>. However, clicking the label also dispatches a click on the native input inside of the label. That click event then bubbles up and gets retargeted. This results in what look like a duplicate click event but is really two separate click events.
There appears to be duplicate click events, but calling composedPath() reveals that the click events are coming from two separate elements.
We have decided not to suppress this behavior because it would mean suppressing what the browser is designed to do.
While you can use composedPath to differentiate the events, I don't recommend doing so because this exposes component internals which are subject to change. In this case, we recommend relying on Ionic events such as ionChange. I also proposed a PR to clarify this behavior on the docs: ionic-team/ionic-docs#2992
I am going to close this, but let me know if there are any questions.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
corysmc commentedon May 18, 2023
Here's a vanilla reproduction as well: https://stackblitz.com/edit/jd93fs?file=index.html
sean-perkins commentedon May 18, 2023
Hello @corysmc thanks for reporting this issue! I can reproduce it with both
ion-checkboxandion-radio. It happens where we have a shadow DOM web component with the modern form control syntax and a label + input.e.g.:
The
labelis the click target. When a label is associated with an input, it will trigger a click on the inner input, which propagates the additional click event.sean-perkins commentedon May 18, 2023
Here is a dev-build to test with:
7.0.8-dev.11684439870.1ade4229Forked reproduction with the dev-build: https://stackblitz.com/edit/8t9ymz-6biavu?file=package.json
corysmc commentedon May 18, 2023
Awesome, thanks @sean-perkins !
implemented QuickFeedbackRating component
chore(fundamentals): clarify events
liamdebeasi commentedon Jun 9, 2023
Hi everyone,
I discussed this with the team, and we have determined this is not a bug in Ionic.
This behavior is happening because the click event is being retargeted as it moves from the Shadow DOM to the Light DOM. In the case of
ion-checkbox, clicking the checkbox dispatches a click on the<label>. However, clicking the label also dispatches a click on the native input inside of the label. That click event then bubbles up and gets retargeted. This results in what look like a duplicate click event but is really two separate click events.You can see this here: https://codepen.io/liamdebeasi/pen/OJaPqpR
There appears to be duplicate click events, but calling composedPath() reveals that the click events are coming from two separate elements.
We have decided not to suppress this behavior because it would mean suppressing what the browser is designed to do.
While you can use
composedPathto differentiate the events, I don't recommend doing so because this exposes component internals which are subject to change. In this case, we recommend relying on Ionic events such asionChange. I also proposed a PR to clarify this behavior on the docs: ionic-team/ionic-docs#2992I am going to close this, but let me know if there are any questions.
ionitron-bot commentedon Jul 9, 2023
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.