(event: React.KeyboardEvent<HTMLInputElement>)
| 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>) => { |
nothing calls this directly
no test coverage detected