-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Description
Steps to reproduce
Steps:
- Open this link to live example: https://stackblitz.com/edit/g2tgc7yt?file=src%2FDemo.tsx
- Click on the text "Tea"
- Check the console. You will see the FormControlLabel onClick handler getting called twice: 1 for label, 1 for the checkbox
Current behavior
Clicking the label inside a FormControlLabel, should not trigger FormControlLabel onClick event twice.
You can see that if you click the checkbox directly, FormControlLabel onClick is called once, not twice.
This can be particularly tricky with analytics in case we forward each click on FormControlLabel to GA or posthog explicitly. It causes duplicated events.
The reason we use FormControlLabel onClick and not Checkbox onClick for this, is because we want to be sure we track any click on the "Checkbox" from a user perspective, regardless of whether they clicked on the checkbox element or the checkbox label. It should count as one click for the purpose of tracking.
Is this intended?
Expected behavior
Clicking on a label inside FormControlLabel should trigger the click once. The event should be the original event. The one from the label.
Context
No response
Your environment
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: FormControlLabel, trigger, twice