diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 77999753..92347ab6 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -369,9 +369,10 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { > { + onSelect={(selectedOption: { label: string; value: string }) => { if (selectedOption.value === "documentation") { window.open(" https://docs.docsgpt.cloud/", "_blank"); } else if (selectedOption.value === "email"){ diff --git a/frontend/src/components/Dropdown.tsx b/frontend/src/components/Dropdown.tsx index 07f33650..b272fd8b 100644 --- a/frontend/src/components/Dropdown.tsx +++ b/frontend/src/components/Dropdown.tsx @@ -47,14 +47,13 @@ function Dropdown({ }) { const dropdownRef = React.useRef(null); const [isOpen, setIsOpen] = React.useState(false); + const [dropdownPosition, setDropdownPosition] = React.useState({ top: 0}); + const borderRadius = rounded === 'xl' ? 'rounded-xl' : 'rounded-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) - ) { + if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setIsOpen(false); } }; @@ -65,56 +64,50 @@ function Dropdown({ document.removeEventListener('mousedown', handleClickOutside); }; }, []); + + const handleToggleDropdown = () => { + setIsOpen(prev => !prev); + if (!isOpen) { + adjustDropdownPosition(); + } + }; + + const adjustDropdownPosition = () => { + if (dropdownRef.current) { + const rect = dropdownRef.current.getBoundingClientRect(); + const dropdownMenuHeight = Math.min(200, options.length * 40); // Adjust height based on options + const viewportHeight = window.innerHeight; + + // Check if dropdown overflows the bottom of the viewport + const newPosition = { + top: rect.bottom + dropdownMenuHeight > viewportHeight ? -dropdownMenuHeight : 0, + left: 0, + }; + + setDropdownPosition(newPosition); + } + }; + return (
{isOpen && (
{options.map((option: any, index) => (
- {typeof option === 'string' - ? option - : option.name - ? option.name - : option.label - ? option.label - : `${ - option.value < 1e9 - ? option.value + ` (${option.description})` - : option.description - }`} + {typeof option === 'string' ? option : option.name || option.label || option.description} {showEdit && onEdit && ( Edit { - onEdit({ - id: option.id, - name: option.name, - type: option.type, - }); + onEdit(option); setIsOpen(false); }} /> @@ -163,11 +142,7 @@ function Dropdown({ Delete )}