(event: KeyboardEvent)
| 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) |
no outgoing calls
no test coverage detected