From 5463b7b58e3a06320be7df0d672039f98edce4e4 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sat, 20 Jan 2024 20:16:26 +0530 Subject: [PATCH] chore: fix super editor menus overflowing --- .../javascripts/Components/NoteView/NoteView.tsx | 2 +- .../Popover/GetPositionedPopoverStyles.ts | 4 ++-- .../javascripts/Components/Popover/Utils/Rect.ts | 2 +- .../Plugins/ToolbarPlugin/ToolbarPlugin.tsx | 16 +++++++++------- .../Components/SuperEditor/SuperEditor.tsx | 2 ++ .../web/src/javascripts/Constants/ElementIDs.ts | 1 + 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx index 776cef8e3..020dd410c 100644 --- a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx +++ b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx @@ -989,7 +989,7 @@ class NoteView extends AbstractComponent { )} {editorMode === 'super' && ( -
+
(percent / 100) * value @@ -154,7 +154,7 @@ export const getPositionedPopoverStyles = ({ ) let maxHeight = getPopoverMaxHeight( - getAppRect(), + documentRect, anchorRect, disableFlip ? side : sideWithLessOverflows, finalAlignment, diff --git a/packages/web/src/javascripts/Components/Popover/Utils/Rect.ts b/packages/web/src/javascripts/Components/Popover/Utils/Rect.ts index cbb59e13e..aefd44703 100644 --- a/packages/web/src/javascripts/Components/Popover/Utils/Rect.ts +++ b/packages/web/src/javascripts/Components/Popover/Utils/Rect.ts @@ -24,7 +24,7 @@ export const getPopoverMaxHeight = ( if (buttonRect) { switch (side) { case 'top': - constraint = appRect.height - buttonRect.top + constraint = Math.abs(appRect.height - buttonRect.top) if (topSafeAreaInset > 0) { constraint += topSafeAreaInset } diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx index da0ee9b56..6b97c2067 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx @@ -65,6 +65,7 @@ import { useStateRef } from '@/Hooks/useStateRef' import { getDOMRangeRect } from '../../Lexical/Utils/getDOMRangeRect' import { getPositionedPopoverStyles } from '@/Components/Popover/GetPositionedPopoverStyles' import usePreference from '@/Hooks/usePreference' +import { ElementIds } from '@/Constants/ElementIDs' const TOGGLE_LINK_AND_EDIT_COMMAND = createCommand('TOGGLE_LINK_AND_EDIT_COMMAND') @@ -503,7 +504,7 @@ const ToolbarPlugin = () => { const [isFocusInEditor, setIsFocusInEditor] = useState(false) const [isFocusInToolbar, setIsFocusInToolbar] = useState(false) - const canShowToolbarOnMobile = isFocusInEditor || isFocusInToolbar + const canShowToolbarOnMobile = true const canShowAllItems = isMobile || isToolbarFixedToTop useEffect(() => { @@ -583,7 +584,8 @@ const ToolbarPlugin = () => { toolbarStore, ]) - const popoverDocumentElement = editor.getRootElement()?.parentElement ?? document.body + const popoverDocumentElement = + document.getElementById(ElementIds.SuperEditor) ?? editor.getRootElement()?.parentElement ?? document.body return ( <> @@ -760,7 +762,7 @@ const ToolbarPlugin = () => { disableMobileFullscreenTakeover disableFlip portal={false} - documentElement={isMobile ? popoverDocumentElement : undefined} + documentElement={popoverDocumentElement} >
Table of Contents
@@ -816,7 +818,7 @@ const ToolbarPlugin = () => { disableFlip containerClassName="md:!min-w-60 md:!w-auto" portal={false} - documentElement={isMobile ? popoverDocumentElement : undefined} + documentElement={popoverDocumentElement} > setIsTextFormatMenuOpen(false)}> { disableFlip containerClassName="md:!min-w-60 md:!w-auto" portal={false} - documentElement={isMobile ? popoverDocumentElement : undefined} + documentElement={popoverDocumentElement} > setIsTextStyleMenuOpen(false)}> { disableFlip containerClassName="md:!min-w-60 md:!w-auto" portal={false} - documentElement={isMobile ? popoverDocumentElement : undefined} + documentElement={popoverDocumentElement} > setIsAlignmentMenuOpen(false)}> { disableFlip containerClassName="md:!min-w-60 md:!w-auto" portal={false} - documentElement={isMobile ? popoverDocumentElement : undefined} + documentElement={popoverDocumentElement} > setIsInsertMenuOpen(false)}> = ({ return (