Skip to content

[FormControlLabel] Clicking on label triggers onClick twice #47326

@rodrigofariow

Description

@rodrigofariow

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/g2tgc7yt?file=src%2FDemo.tsx
  2. Click on the text "Tea"
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: FormControlThe React component.has workaroundThere’s a bug, but users have a complete workaround, so no urgent fix or release is needed.type: expected behaviorThe current behavior is already the one expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions