Skip to content

Commit

Permalink
Fix/floating formatter #5021 (#5041)
Browse files Browse the repository at this point in the history
Co-authored-by: Manthan Gaikwad <87421766+manthanG369@users.noreply.github.com>
Co-authored-by: Amruta24818 <99421265+Amruta24818@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent 7b953ca commit 9a272fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ function TextFormatFloatingToolbar({
) {
const rangeRect = getDOMRangeRect(nativeSelection, rootElement);

setFloatingElemPosition(rangeRect, popupCharStylesEditorElem, anchorElem);
setFloatingElemPosition(
rangeRect,
popupCharStylesEditorElem,
anchorElem,
isLink,
);
}
}, [editor, anchorElem]);
}, [editor, anchorElem, isLink]);

useEffect(() => {
const scrollerElem = anchorElem.parentElement;
Expand Down Expand Up @@ -355,7 +360,7 @@ function useFloatingTextFormatToolbar(
);
}, [editor, updatePopup]);

if (!isText || isLink) {
if (!isText) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function setFloatingElemPosition(
targetRect: DOMRect | null,
floatingElem: HTMLElement,
anchorElem: HTMLElement,
isLink: boolean = false,
verticalGap: number = VERTICAL_GAP,
horizontalOffset: number = HORIZONTAL_OFFSET,
): void {
Expand All @@ -31,7 +32,11 @@ export function setFloatingElemPosition(
let left = targetRect.left - horizontalOffset;

if (top < editorScrollerRect.top) {
top += floatingElemRect.height + targetRect.height + verticalGap * 2;
// adjusted height for link element if the element is at top
top +=
floatingElemRect.height +
targetRect.height +
verticalGap * (isLink ? 9 : 2);
}

if (left + floatingElemRect.width > editorScrollerRect.right) {
Expand Down

1 comment on commit 9a272fa

@vercel
Copy link

@vercel vercel bot commented on 9a272fa Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-fbopensource.vercel.app
lexicaljs.com
lexical-git-main-fbopensource.vercel.app
www.lexical.dev
lexical.dev
lexicaljs.org

Please sign in to comment.