From c85fb04151635dd7b01d1e2e2157133f9126775f Mon Sep 17 00:00:00 2001 From: Dzianis Lean Date: Thu, 10 Mar 2022 09:52:37 +0300 Subject: [PATCH 1/2] docs: keyPress warning --- docs/dom-testing-library/api-events.mdx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/dom-testing-library/api-events.mdx b/docs/dom-testing-library/api-events.mdx index 8801f9c24..db1ad07ff 100644 --- a/docs/dom-testing-library/api-events.mdx +++ b/docs/dom-testing-library/api-events.mdx @@ -96,6 +96,9 @@ fireEvent.keyDown(domNode, {key: 'Enter', code: 'Enter', charCode: 13}) fireEvent.keyDown(domNode, {key: 'A', code: 'KeyA'}) ``` +> :warning: Be careful to provide the `charCode` property in case of firing the +> `keyPress` event. Otherwise, it won't be fired. + You can find out which key code to use at [https://keycode.info/](https://keycode.info/). From 2300b3c020f57b6dfff51162b9bcf4e1cc72a359 Mon Sep 17 00:00:00 2001 From: "Owrlean .D" <12446451+Owrlean@users.noreply.github.com> Date: Thu, 10 Mar 2022 15:45:21 +0300 Subject: [PATCH 2/2] Update docs/dom-testing-library/api-events.mdx Co-authored-by: Philipp Fritsche --- docs/dom-testing-library/api-events.mdx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/dom-testing-library/api-events.mdx b/docs/dom-testing-library/api-events.mdx index db1ad07ff..4f7d3fe1b 100644 --- a/docs/dom-testing-library/api-events.mdx +++ b/docs/dom-testing-library/api-events.mdx @@ -96,9 +96,8 @@ fireEvent.keyDown(domNode, {key: 'Enter', code: 'Enter', charCode: 13}) fireEvent.keyDown(domNode, {key: 'A', code: 'KeyA'}) ``` -> :warning: Be careful to provide the `charCode` property in case of firing the -> `keyPress` event. Otherwise, it won't be fired. - +> :warning: `React` doesn't dispatch a `SyntheticEvent` for a native `keypress` event without `event.charCode === 13 || event.charCode >= 32`. +> I.e. `onKeyPress` handlers will only be called if you include an appropriate `charCode` property. You can find out which key code to use at [https://keycode.info/](https://keycode.info/).