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

Đang mở
#139 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
frontend, testing-qa

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
537
Fork
22
Merge trung bình
11 giờ 37 phút
Pull request đã merge (30 ngày)
35

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/redact

Tất cả issue của TanStack/redact

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.