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
feat(fire-event): warn when firing events on disabled elements
Firing an event on a disabled element (e.g. a `Pressable` with
`disabled={true}`) silently triggers no handler, which is confusing when
debugging tests. Emit a warning in that case, reusing `computeAriaDisabled`
for detection and the existing `logger`.
- Gated on no handler being found, so events that bubble to an enabled
parent do not warn.
- Scoped to disabled state only; `pointerEvents="none"` and `TextInput`
editability are intentionally excluded to avoid false positives.
- Opt-out via `configure({ disabledEventWarning: false })`; on by default.
Closes#1718 (fireEvent scope; userEvent is a follow-up).
Copy file name to clipboardExpand all lines: website/docs/14.x/docs/api/misc/config.mdx
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,9 @@ type Config = {
10
10
/** Default value for `includeHiddenElements` query option. */
11
11
defaultIncludeHiddenElements:boolean;
12
12
13
+
/** Warn when firing an event on a disabled element triggers no handler. */
14
+
disabledEventWarning:boolean;
15
+
13
16
/** Default options for `debug` helper. */
14
17
defaultDebugOptions?:Partial<DebugOptions>;
15
18
};
@@ -32,6 +35,14 @@ Default value for [includeHiddenElements](/docs/api/queries#includehiddenelement
32
35
33
36
This option is also available as `defaultHidden` alias for compatibility with [React Testing Library](https://testing-library.com/docs/dom-testing-library/api-configuration/#defaulthidden).
34
37
38
+
### `disabledEventWarning` option
39
+
40
+
When `fireEvent` is used on a disabled element (e.g. a `Pressable` with `disabled={true}`) the event is not dispatched to any handler, which can be surprising while debugging tests. When this option is enabled (the default), a warning is logged in that case. Set it to `false` to opt out:
41
+
42
+
```ts
43
+
configure({ disabledEventWarning: false });
44
+
```
45
+
35
46
### `defaultDebugOptions` option
36
47
37
48
Default [debug options](#debug) to be used when calling `debug()`. These default options will be overridden by the ones you specify directly when calling `debug()`.
0 commit comments