File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
client/src/components/Shared/SearchBar Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ const SearchBar: React.FC<SearchBarProps> = ({ handleSubmit }) => {
36
36
}
37
37
38
38
// support searching for terms that the API may not return (add user's typed term to options if it's not already there)
39
- if (
39
+ if ( typedSearchTerm &&
40
40
autocompleteOptions . filter (
41
41
( option : { suggestion : string } ) => option . suggestion === typedSearchTerm
42
- ) . length === 0
42
+ ) . length === 0 && typedSearchTerm . trim ( ) !== ""
43
43
) {
44
44
autocompleteOptions = [
45
45
{ suggestion : typedSearchTerm } ,
@@ -125,6 +125,13 @@ const SearchBar: React.FC<SearchBarProps> = ({ handleSubmit }) => {
125
125
}
126
126
} , [ selectedOptions ] ) ;
127
127
128
+ const handlePaste = ( event : any ) => {
129
+ const pastedOptions = event . clipboardData . getData ( "text" ) . split ( "," ) . map ( ( item : string ) => { return { suggestion : item . trim ( ) } } ) ;
130
+ setSelectedOptions ( pastedOptions ) ;
131
+ // we don't want the code to also run what's in onInputChange for the Autocomplete since everything is handled here
132
+ event . preventDefault ( )
133
+ }
134
+
128
135
return (
129
136
< >
130
137
< Box id = "search-bar-container" width = { isMobile ? '95%' : '75%' } >
@@ -155,6 +162,7 @@ const SearchBar: React.FC<SearchBarProps> = ({ handleSubmit }) => {
155
162
< Box >
156
163
< TextField
157
164
{ ...params }
165
+ onPaste = { handlePaste }
158
166
variant = "standard"
159
167
label = "Search Terms"
160
168
/>
You can’t perform that action at this time.
0 commit comments