Просмотр исходного кода

fix(search): correctly set preventDownshiftDefault on native event for Home/End keys

Yuki Takei 1 месяц назад
Родитель
Сommit
93de9ef10d

+ 1 - 3
apps/app/src/features/search/client/components/SearchForm.tsx

@@ -46,9 +46,7 @@ export const SearchForm = (props: Props): JSX.Element => {
   const keyDownHandler = useCallback(
     (e: React.KeyboardEvent<HTMLInputElement>) => {
       if (e.key === 'Home' || e.key === 'End') {
-        (
-          e.nativeEvent as { preventDownshiftDefault?: boolean }
-        ).preventDownshiftDefault = true;
+        e.nativeEvent.preventDownshiftDefault = true;
       }
     },
     [],

+ 9 - 0
apps/app/src/features/search/client/interfaces/downshift.ts

@@ -1,5 +1,14 @@
 import type { ControllerStateAndHelpers } from 'downshift';
 
+// Augment the global Event interface with downshift's custom property.
+// downshift checks event.nativeEvent.preventDownshiftDefault to skip
+// its default key handling. See: https://www.downshift-js.com/downshift#customizing-handlers
+declare global {
+  interface Event {
+    preventDownshiftDefault?: boolean;
+  }
+}
+
 export type DownshiftItem = { url: string };
 
 export type GetItemProps =