MCPcopy Create free account
hub / github.com/dailydotdev/apps / onPress

Function onPress

packages/shared/src/hooks/useKeyboardNavigation.ts:23–58  ·  view source on GitHub ↗
(nativeEvent)

Source from the content-addressed store, hash-verified

21 }
22
23 const onPress: EventListener = (nativeEvent) => {
24 const e = nativeEvent as KeyboardEvent & { path?: EventTarget[] };
25 const [base] =
26 (e.composedPath?.() as HTMLElement[]) ||
27 (e.path as HTMLElement[]) ||
28 [];
29 const tagName =
30 base?.tagName.toLowerCase() as keyof JSX.IntrinsicElements;
31 if (optional?.disableOnTags?.includes(tagName)) {
32 return;
33 }
34
35 if (
36 optional.disabledModalOpened &&
37 ((element as HTMLElement).querySelector?.(MODAL_SELECTOR) ||
38 (element as Window).document?.querySelector?.(MODAL_SELECTOR))
39 ) {
40 return;
41 }
42
43 if (base.getAttribute('contenteditable') === 'true') {
44 return;
45 }
46
47 if (isSpecialKeyPressed({ event: e })) {
48 return;
49 }
50
51 const matchedEvent = events.find(([key]) => key === e.key);
52
53 if (!matchedEvent) {
54 return;
55 }
56
57 matchedEvent[1](e);
58 };
59
60 element.addEventListener('keydown', onPress);
61

Callers

nothing calls this directly

Calls 1

isSpecialKeyPressedFunction · 0.90

Tested by

no test coverage detected