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
{{ message }}
Repository navigation
Disabled checkbox inside a label still triggers onChange method when clicked #1234
Render a component with an <input type="checkbox" onChange={yourFunc} disabled /> inside a <label>.
Click any element inside the <label> (or the label itself).
Expected behavior
The onChange method of the checkbox should not be called, as the checkbox is disabled.
Actual behavior
The onChange method of the checkbox is being called.
User-event version
14.5.2
Environment
If the Codesandbox is not available, it is easily reproducible by a single test file:
import "@testing-library/jest-dom";
import { render } from "@testing-library/react";
import { screen } from "@testing-library/dom";
import { userEvent } from "@testing-library/user-event";
describe("Checkbox", () => {
it("does not execute onChange if checkbox is disabled", async () => {
const onChange = vi.fn(); // also reproducible with jest.fn();
render(
<label>
<input type="checkbox" onChange={onChange} data-testid="input" disabled />
<span>My label</span>
</label>
);
await userEvent.click(screen.getByText("My label"));
expect(onChange).not.toHaveBeenCalled(); // this fails
});
});
Additional context
If the same test is performed but using the onClick event, the test is successful and the event is not called. However, onChange should not be called either. When trying this same scenario in a real browser, onChange is correctly ignored.
I tried the React example on both versions with React 18 and jsdom 20. On 14.5.2, clicking the span or the label checked the disabled input and fired one onChange. On 14.6.1, it stayed unchecked with zero calls. The enabled checkbox still fired once when clicked through either element. Chromium, Firefox and WebKit gave the same result as 14.6.1 for both states.
#1130 shipped in 14.6.1 and covers this case. Updating @testing-library/user-event to that version fixed the reproduction here.
Activity
yucheng-du commentedon Dec 2, 2026
I tried the React example on both versions with React 18 and jsdom 20. On 14.5.2, clicking the span or the label checked the disabled input and fired one
onChange. On 14.6.1, it stayed unchecked with zero calls. The enabled checkbox still fired once when clicked through either element. Chromium, Firefox and WebKit gave the same result as 14.6.1 for both states.#1130 shipped in 14.6.1 and covers this case. Updating
@testing-library/user-eventto that version fixed the reproduction here.snowystinger commentedon Dec 2, 2026
Thanks, I'm going to close this. I've added a PR to add an explicit regression test for it later as well #1361