Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking on a label element of a checkbox does not trigger checkbox #1230

Open
JunyeongChoi0 opened this issue Jul 26, 2024 · 1 comment
Open
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member

Comments

@JunyeongChoi0
Copy link

Reproduction example

https://codesandbox.io/p/devbox/elated-gould-h5tv93

Prerequisites

  1. Render <label><span>label</span><input type="checkbox" /></label>
  2. Find label element
  3. Click on label element
  4. Watch whether checkbox checked

Expected behavior

The checkbox should be checked.

Actual behavior

The checkbox is still unchecked.

User-event version

14.5.2

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

@JunyeongChoi0 JunyeongChoi0 added bug Something isn't working needs assessment This needs to be looked at by a team member labels Jul 26, 2024
@LucidityDesign
Copy link

Same here. "CLICK" gets logged but the test fails:

import { fireEvent, render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"

const user = userEvent.setup()

test('click', async () => {
  render(
    <div>
      <label htmlFor="checkbox" onClick={() => console.log("CLICK")}>Check</label>
      <input id="checkbox" type="checkbox" />
    </div>,
  )

  await user.click(screen.getByText('Check'))
  // fireEvent.click(screen.getByText('Check'))
  expect(screen.getByLabelText('Check')).toBeChecked()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member
Projects
None yet
Development

No branches or pull requests

2 participants