Dispatched mouse events call onClick/onMouseDown on disabled buttons (React skips them)

未关闭
#139 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start by reproducing the issue with the supplied Vitest, jsdom, and Testing Library example, then read React DOM's shouldPreventMouseEvent behavior and find the corresponding event-dispatch path in Redact. Done when dispatched mouse events do not call handlers on disabled button, input, select, or textarea elements, and the regression test passes.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
537
派生
22
平均合并
10 小时 27 分钟
30 天内合并 PR
40

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/redact 的其他 Issue

查看 TanStack/redact 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。