mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
fix: dropdown closes on clicking outside
This commit is contained in:
@@ -42,9 +42,26 @@ function Dropdown({
|
|||||||
onDelete?: (value: string) => void;
|
onDelete?: (value: string) => void;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
}) {
|
}) {
|
||||||
|
const dropdownRef = React.useRef<HTMLDivElement>(null);
|
||||||
const [isOpen, setIsOpen] = React.useState(false);
|
const [isOpen, setIsOpen] = React.useState(false);
|
||||||
const borderRadius = rounded === 'xl' ? 'rounded-xl' : 'rounded-3xl';
|
const borderRadius = rounded === 'xl' ? 'rounded-xl' : 'rounded-3xl';
|
||||||
const borderTopRadius = rounded === 'xl' ? 'rounded-t-xl' : 'rounded-t-3xl';
|
const borderTopRadius = rounded === 'xl' ? 'rounded-t-xl' : 'rounded-t-3xl';
|
||||||
|
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (
|
||||||
|
dropdownRef.current &&
|
||||||
|
!dropdownRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
setIsOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={[
|
className={[
|
||||||
@@ -53,6 +70,7 @@ function Dropdown({
|
|||||||
: 'relative align-middle',
|
: 'relative align-middle',
|
||||||
size,
|
size,
|
||||||
].join(' ')}
|
].join(' ')}
|
||||||
|
ref={dropdownRef}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
onClick={() => setIsOpen(!isOpen)}
|
onClick={() => setIsOpen(!isOpen)}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import React from 'react';
|
||||||
import Trash from '../assets/trash.svg';
|
import Trash from '../assets/trash.svg';
|
||||||
import Arrow2 from '../assets/dropdown-arrow.svg';
|
import Arrow2 from '../assets/dropdown-arrow.svg';
|
||||||
import { Doc } from '../preferences/preferenceApi';
|
import { Doc } from '../preferences/preferenceApi';
|
||||||
@@ -21,6 +22,8 @@ function SourceDropdown({
|
|||||||
handleDeleteClick,
|
handleDeleteClick,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const dropdownRef = React.useRef<HTMLDivElement>(null);
|
||||||
const embeddingsName =
|
const embeddingsName =
|
||||||
import.meta.env.VITE_EMBEDDINGS_NAME ||
|
import.meta.env.VITE_EMBEDDINGS_NAME ||
|
||||||
'huggingface_sentence-transformers/all-mpnet-base-v2';
|
'huggingface_sentence-transformers/all-mpnet-base-v2';
|
||||||
@@ -30,10 +33,23 @@ function SourceDropdown({
|
|||||||
setIsDocsListOpen(false);
|
setIsDocsListOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (
|
||||||
|
dropdownRef.current &&
|
||||||
|
!dropdownRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
setIsDocsListOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div className="relative w-5/6 rounded-3xl">
|
<div className="relative w-5/6 rounded-3xl" ref={dropdownRef}>
|
||||||
<button
|
<button
|
||||||
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
||||||
className={`flex w-full cursor-pointer items-center border border-silver bg-white p-[14px] dark:bg-transparent ${
|
className={`flex w-full cursor-pointer items-center border border-silver bg-white p-[14px] dark:bg-transparent ${
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ export default function Conversation() {
|
|||||||
<div
|
<div
|
||||||
onWheel={handleUserInterruption}
|
onWheel={handleUserInterruption}
|
||||||
onTouchMove={handleUserInterruption}
|
onTouchMove={handleUserInterruption}
|
||||||
className="flex h-[90%] w-full justify-center overflow-y-auto p-4 md:h-[84vh]"
|
className="flex h-[90%] w-full justify-center overflow-y-auto p-4 md:h-[83vh]"
|
||||||
>
|
>
|
||||||
{queries.length > 0 && !hasScrolledToLast && (
|
{queries.length > 0 && !hasScrolledToLast && (
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user