Skip to content

Commit 26ee41e

Browse files
committed
fix(switch): type the web Space handlers with React Native key events
React Native 0.88 types `onKeyDown` and `onKeyUp` as `KeyDownEvent` and `KeyUpEvent`, so the DOM `KeyboardEvent` annotations no longer type check. The handlers only read `nativeEvent.key`, `nativeEvent.repeat` and `preventDefault()`, which both React Native's event and the React synthetic event that React Native Web passes provide.
1 parent 15bdd3d commit 26ee41e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/components/Switch/Switch.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22
import {
3+
type KeyDownEvent,
4+
type KeyUpEvent,
35
Platform,
46
Pressable,
57
StyleSheet,
@@ -415,7 +417,7 @@ const Switch = ({
415417
// React Native Web only handles Space for button roles.
416418
...(Platform.OS === 'web'
417419
? {
418-
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {
420+
onKeyDown: (event: KeyDownEvent) => {
419421
const { key, repeat } = event.nativeEvent;
420422
if (key !== ' ' && key !== 'Spacebar') return;
421423
event.preventDefault();
@@ -424,7 +426,7 @@ const Switch = ({
424426
pressedSV.value = 1;
425427
}
426428
},
427-
onKeyUp: (event: React.KeyboardEvent<HTMLElement>) => {
429+
onKeyUp: (event: KeyUpEvent) => {
428430
const { key } = event.nativeEvent;
429431
if (key !== ' ' && key !== 'Spacebar') return;
430432
event.preventDefault();

0 commit comments

Comments
 (0)