MCPcopy Create free account
hub / github.com/SyntaxUI/syntaxui / handleKeyDown

Function handleKeyDown

src/showcase/components/input/TagInput.tsx:20–40  ·  view source on GitHub ↗
(event: React.KeyboardEvent<HTMLInputElement>)

Source from the content-addressed store, hash-verified

18
19 // Handles adding new keyword on Enter or comma press, and keyword removal on Backspace
20 const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
21 if (
22 (event.key === 'Enter' || event.key === ',') &&
23 inputValue.trim() !== ''
24 ) {
25 event.preventDefault()
26 const newKeyword = inputValue.trim()
27 const newKeywords = unique
28 ? [...new Set([...keywords, newKeyword])]
29 : [...keywords, newKeyword]
30
31 setKeywords(newKeywords)
32 onKeywordsChange(newKeywords)
33 setInputValue('')
34 } else if (event.key === 'Backspace' && inputValue === '') {
35 event.preventDefault()
36 const newKeywords = keywords.slice(0, -1)
37 setKeywords(newKeywords)
38 onKeywordsChange(newKeywords)
39 }
40 }
41
42 // Handles pasting keywords separated by commas, new lines, or tabs
43 const handlePaste = (event: React.ClipboardEvent<HTMLInputElement>) => {

Callers

nothing calls this directly

Calls 1

onKeywordsChangeFunction · 0.85

Tested by

no test coverage detected