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

Aperta
#139 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, react, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
537
Fork
22
Merge medio
11h 37m
PR unite (30g)
35

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/redact

Tutte le issue di TanStack/redact

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.