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

Checkbox should not be checked when clicking Label of disabled checkbox #1057

Open
JesseChain opened this issue Sep 16, 2022 · 6 comments · May be fixed by #1130
Open

Checkbox should not be checked when clicking Label of disabled checkbox #1057

JesseChain opened this issue Sep 16, 2022 · 6 comments · May be fixed by #1130
Labels
bug Something isn't working

Comments

@JesseChain
Copy link

JesseChain commented Sep 16, 2022

Reproduction example

https://codesandbox.io/s/sparkling-sky-5g3t2j?file=/src/App.test.js

Prerequisites

  1. Render <label><input type="checkbox" disabled /> Disabled Checkbox</label>
  2. Click on the label element

Expected behavior

checkbox should not be checked

Actual behavior

checkbox is checked

User-event version

14.4.3

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

@JesseChain JesseChain added bug Something isn't working needs assessment This needs to be looked at by a team member labels Sep 16, 2022
@ph-fritsche ph-fritsche removed the needs assessment This needs to be looked at by a team member label Sep 16, 2022
@bradlocking
Copy link

Also able to replicate using v14.3.3. Working example here - with tests passing when selecting a text input, text input label and hitting the checkbox directly, so it's isolated to the label of a checkbox input

@shdq
Copy link

shdq commented Mar 2, 2023

Hey there! I confirm the problem.

"@testing-library/user-event": "^14.4.3"

Test sample

const user = userEvent.setup();

test("should be unchecked after the click on disabled label", async () => {
  // Arrange
  render(<Checkbox disabled label="My label" />);
  const label = screen.getByText("My label");
  const checkbox = screen.getByLabelText("My label");

  // Act & Assert
  expect(checkbox).not.toBeChecked();
  await user.click(label);
  expect(checkbox).not.toBeChecked(); // fails on this line...
});

@thinhdev97
Copy link

Hi there. I got the same issue with radio. "@testing-library/user-event": "^14.4.3" 😢

@nknapp
Copy link

nknapp commented Apr 12, 2023

Similar example with plain jsdom: https://stackblitz.com/edit/vitest-dev-vitest-azkvzh?file=test/basic.test.ts

From a very naive point of view, I would say that line 12 and 13 in click.ts should be swapped, so that the click is only dispatched if the "control" was successfully focused.

a0js pushed a commit to a0js/user-event that referenced this issue May 11, 2023
When a label with a control is clicked, the click is forwarded even if
the control is not focusable (i.e. disabled or hidden). This change
addresses that issue.

Resolves testing-library#1057

Also, updating the how to contribute tutorial link in CONTRIBUTING.md.
a0js pushed a commit to a0js/user-event that referenced this issue May 11, 2023
When a label with a control is clicked, the click is forwarded even if
the control is not focusable (i.e. disabled or hidden). This change
addresses that issue.

Resolves testing-library#1057

Also, updating the how to contribute tutorial link in CONTRIBUTING.md.
a0js added a commit to a0js/user-event that referenced this issue May 11, 2023
When a label with a control is clicked, the click is forwarded even if
the control is not focusable (i.e. disabled or hidden). This change
addresses that issue.

Resolves testing-library#1057

Also, updating the how to contribute tutorial link in CONTRIBUTING.md.
a0js added a commit to a0js/user-event that referenced this issue May 11, 2023
When a label with a control is clicked, the click is forwarded even if
the control is not focusable (i.e. disabled or hidden). This change
addresses that issue.

Resolves testing-library#1057

Also, updating the how to contribute tutorial link in CONTRIBUTING.md.
@a0js a0js linked a pull request May 11, 2023 that will close this issue
2 tasks
@alexander-xyz
Copy link

I have the same problem after I upgraded to last version 14.4.3 from 13.5.0. In 13.5.0 it works as expected. Fix it, please.

@sean6bucks
Copy link

Had to downgrade to 13.5.0 to unblock my tests (instead of using fireEvent which works), would love if the above posted MR to fix could get some love.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants