MCPcopy Create free account
hub / github.com/primer/react / onKeyDown

Function onKeyDown

packages/react/src/TreeView/useTypeahead.ts:64–82  ·  view source on GitHub ↗
(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

62 const container = containerRef.current
63
64 function onKeyDown(event: KeyboardEvent) {
65 // Ignore key presses that don't produce a character value
66 if (!event.key || event.key.length > 1) return
67
68 // Ignore key presses that occur with a modifier
69 if (event.ctrlKey || event.altKey || event.metaKey) return
70
71 // Update the existing search value with the new key press
72 searchValue.current += event.key
73 focusSearchValue(searchValue.current)
74
75 // Reset the timeout
76 safeClearTimeout(timeoutRef.current)
77 timeoutRef.current = safeSetTimeout(() => (searchValue.current = ''), 300)
78
79 // Prevent default behavior
80 event.preventDefault()
81 event.stopPropagation()
82 }
83
84 container.addEventListener('keydown', onKeyDown)
85 return () => container.removeEventListener('keydown', onKeyDown)

Callers 2

TokenBase.tsxFile · 0.50
handleInputKeyDownFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected