Main Menu Dropdown: Fix width (#6902)

This commit is contained in:
Alexander Zinchuk 2026-05-05 13:46:22 +02:00
parent 889bca140d
commit ee6f56ce7a
3 changed files with 42 additions and 5 deletions

View File

@ -68,6 +68,7 @@ const LeftSideMenuDropdown = ({
positionX={shouldHideSearch && lang.isRtl ? 'right' : 'left'} positionX={shouldHideSearch && lang.isRtl ? 'right' : 'left'}
transformOriginX={90} transformOriginX={90}
transformOriginY={100} transformOriginY={100}
withPortal
onTransitionEnd={lang.isRtl ? handleDropdownMenuTransitionEnd : undefined} onTransitionEnd={lang.isRtl ? handleDropdownMenuTransitionEnd : undefined}
> >
<LeftSideMenuItems <LeftSideMenuItems

View File

@ -126,11 +126,6 @@
transform: scale(0.75); transform: scale(0.75);
} }
.Menu .bubble {
overflow-y: auto;
max-height: calc(100 * var(--vh) - 3.75rem);
}
.extra-spacing { .extra-spacing {
position: relative; position: relative;
margin-left: 0.5rem; margin-left: 0.5rem;
@ -181,7 +176,10 @@
left: auto; left: auto;
} }
} }
}
#LeftMainHeader,
.Menu.main-menu.in-portal {
.account-menu-item { .account-menu-item {
--custom-emoji-size: 1rem; --custom-emoji-size: 1rem;
@ -200,6 +198,11 @@
margin-inline: 0.375rem 1.125rem; margin-inline: 0.375rem 1.125rem;
} }
.title {
overflow: hidden;
min-width: 0;
}
.fullName { .fullName {
margin: 0; margin: 0;
padding-top: 0.1875rem; padding-top: 0.1875rem;
@ -208,3 +211,10 @@
} }
} }
} }
#LeftMainHeader .Menu.main-menu .bubble,
.Menu.main-menu.in-portal .bubble {
overflow-y: auto;
max-width: 20rem;
max-height: calc(100 * var(--vh) - 3.75rem);
}

View File

@ -4,6 +4,10 @@ import {
useCallback, useMemo, useRef, useState, useCallback, useMemo, useRef, useState,
} from '../../lib/teact/teact'; } from '../../lib/teact/teact';
import type { IAnchorPosition } from '../../types';
import useLastCallback from '../../hooks/useLastCallback';
import Button from './Button'; import Button from './Button';
import Menu from './Menu'; import Menu from './Menu';
@ -49,9 +53,16 @@ const DropdownMenu: FC<OwnProps> = ({
autoClose = true, autoClose = true,
}) => { }) => {
const menuRef = useRef<HTMLDivElement>(); const menuRef = useRef<HTMLDivElement>();
const triggerRef = useRef<HTMLDivElement>();
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [menuAnchor, setMenuAnchor] = useState<IAnchorPosition | undefined>();
const toggleIsOpen = () => { const toggleIsOpen = () => {
if (!isOpen && withPortal && triggerRef.current) {
const rect = triggerRef.current.getBoundingClientRect();
setMenuAnchor({ x: rect.left, y: rect.bottom });
}
setIsOpen(!isOpen); setIsOpen(!isOpen);
if (isOpen) { if (isOpen) {
@ -97,8 +108,16 @@ const DropdownMenu: FC<OwnProps> = ({
); );
}, [trigger]); }, [trigger]);
const getTriggerElement = useLastCallback(() => triggerRef.current);
const getRootElement = useLastCallback(() => document.body);
const getMenuElement = useLastCallback(
() => menuRef.current?.querySelector('.bubble') as HTMLElement | undefined,
);
const getLayout = useLastCallback(() => ({ withPortal: true }));
return ( return (
<div <div
ref={triggerRef}
className={`DropdownMenu ${className || ''}`} className={`DropdownMenu ${className || ''}`}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
onTransitionEnd={onTransitionEnd} onTransitionEnd={onTransitionEnd}
@ -120,6 +139,13 @@ const DropdownMenu: FC<OwnProps> = ({
onClose={handleClose} onClose={handleClose}
onCloseAnimationEnd={onHide} onCloseAnimationEnd={onHide}
onMouseEnterBackdrop={onMouseEnterBackdrop} onMouseEnterBackdrop={onMouseEnterBackdrop}
{...(withPortal && menuAnchor ? {
anchor: menuAnchor,
getTriggerElement,
getRootElement,
getMenuElement,
getLayout,
} : undefined)}
> >
{children} {children}
</Menu> </Menu>