Kamil Furtak
commited on
Commit
·
e717d25
1
Parent(s):
2056625
Add click outside handler to close ModelSelector dropdown
Browse files
app/components/chat/ModelSelector.tsx
CHANGED
|
@@ -30,6 +30,20 @@ export const ModelSelector = ({
|
|
| 30 |
const [focusedIndex, setFocusedIndex] = useState(-1);
|
| 31 |
const searchInputRef = useRef<HTMLInputElement>(null);
|
| 32 |
const optionsRef = useRef<(HTMLDivElement | null)[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
// Filter models based on search query
|
| 35 |
const filteredModels = [...modelList]
|
|
@@ -176,7 +190,7 @@ export const ModelSelector = ({
|
|
| 176 |
))}
|
| 177 |
</select>
|
| 178 |
|
| 179 |
-
<div className="relative flex-1 lg:max-w-[70%]" onKeyDown={handleKeyDown}>
|
| 180 |
<div
|
| 181 |
className={classNames(
|
| 182 |
'w-full p-2 rounded-lg border border-bolt-elements-borderColor',
|
|
|
|
| 30 |
const [focusedIndex, setFocusedIndex] = useState(-1);
|
| 31 |
const searchInputRef = useRef<HTMLInputElement>(null);
|
| 32 |
const optionsRef = useRef<(HTMLDivElement | null)[]>([]);
|
| 33 |
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
| 34 |
+
|
| 35 |
+
useEffect(() => {
|
| 36 |
+
const handleClickOutside = (event: MouseEvent) => {
|
| 37 |
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
| 38 |
+
setIsModelDropdownOpen(false);
|
| 39 |
+
setModelSearchQuery('');
|
| 40 |
+
}
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
document.addEventListener('mousedown', handleClickOutside);
|
| 44 |
+
|
| 45 |
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
| 46 |
+
}, []);
|
| 47 |
|
| 48 |
// Filter models based on search query
|
| 49 |
const filteredModels = [...modelList]
|
|
|
|
| 190 |
))}
|
| 191 |
</select>
|
| 192 |
|
| 193 |
+
<div className="relative flex-1 lg:max-w-[70%]" onKeyDown={handleKeyDown} ref={dropdownRef}>
|
| 194 |
<div
|
| 195 |
className={classNames(
|
| 196 |
'w-full p-2 rounded-lg border border-bolt-elements-borderColor',
|