diff --git a/frontend/src/components/PostMenu.jsx b/frontend/src/components/PostMenu.jsx index 9a49001..7160f66 100644 --- a/frontend/src/components/PostMenu.jsx +++ b/frontend/src/components/PostMenu.jsx @@ -159,14 +159,39 @@ export default function PostMenu({ post, currentUser, onClose, onDelete, onUpdat ) } - const menuStyle = buttonPosition ? { - position: 'fixed', - top: `${buttonPosition.bottom + 4}px`, - left: `${buttonPosition.left + (buttonPosition.right - buttonPosition.left) / 2}px`, - transform: 'translateX(-50%)', - width: 'auto', - minWidth: '140px' - } : {} + const getMenuStyle = () => { + if (!buttonPosition) return {} + + const menuWidth = 160 // Примерная ширина меню + const padding = 8 // Отступ от края экрана + const buttonCenterX = buttonPosition.left + (buttonPosition.right - buttonPosition.left) / 2 + const windowWidth = window.innerWidth + + let left = buttonCenterX + let transform = 'translateX(-50%)' + + // Проверка правого края + if (buttonCenterX + menuWidth / 2 > windowWidth - padding) { + left = windowWidth - padding - menuWidth / 2 + transform = 'translateX(-50%)' + } + + // Проверка левого края + if (buttonCenterX - menuWidth / 2 < padding) { + left = padding + menuWidth / 2 + transform = 'translateX(-50%)' + } + + return { + position: 'fixed', + top: `${buttonPosition.bottom + 4}px`, + left: `${left}px`, + transform: transform, + width: 'auto', + minWidth: '140px', + maxWidth: `${windowWidth - padding * 2}px` + } + } return createPortal(
e.stopPropagation()} onClick={handleOverlayClick} > -
e.stopPropagation()}> +
e.stopPropagation()}>
e.stopPropagation()}> - {isOwnPost || isModerator ? ( + {(isOwnPost || isModerator) && ( <> - + {isOwnPost && ( + + )} - ) : ( + )} + {!isOwnPost && (