Dispatched mouse events call onClick/onMouseDown on disabled buttons (React skips them) #139
Version: @tanstack/redact 0.2.5
A dispatched click on a disabled <button> calls its onClick under Redact. React doesn't: its event system skips mouse events (onClick, onMouseDown, onMouseUp, onDoubleClick, …) on disabled button, input, select and textarea elements (shouldPreventMouseEvent in React DOM).
Real user clicks are unaffected, because browsers don't deliver them to disabled form controls. But element.dispatchEvent(new MouseEvent("click")) and Testing Library's fireEvent.click do reach the element, so tests asserting that a disabled button does nothing fail under Redact.
Repro (Vitest + jsdom + Testing Library)#
// @vitest-environment jsdom
import { render, fireEvent } from "@testing-library/react";
import { expect, it, vi } from "vitest";
it("does not call onClick on a disabled button", () => {
const onClick = vi.fn();
const onMouseDown = vi.fn();
const { getByRole } = render(
<button disabled onClick={onClick} onMouseDown={onMouseDown}>Send</button>
);
const button = getByRole("button");
fireEvent.click(button);
fireEvent.mouseDown(button);
button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(onClick).not.toHaveBeenCalled();
expect(onMouseDown).not.toHaveBeenCalled();
});
onClick calls | onMouseDown calls | |
|---|---|---|
| React 19 | 0 ✅ | 0 ✅ |
| Redact 0.2.5 | 2 ❌ | 1 ❌ |
Expected#
Like React: don't dispatch mouse event handlers to a disabled button/input/select/textarea (or to handlers on the disabled element when the event targets it).
Found in a TanStack Start app: a test checks that a "send" button stays inert while an earlier send is still unclear (disabled set, then fireEvent.click). It passes under React and fails under Redact.
Sign in to join this conversation.
Thanks for the clear reproduction. This is confirmed, and a candidate fix now matches React in the browser checks.