Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-18770] Fix - Allow LinkMenu to flip so it's not cut off if there's not enough space #578

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/slate-editor/src/components/Portals/BasePortalV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const BasePortalV2: FunctionComponent<Props> = ({
});
}

const { attributes, styles } = usePopper(referenceElement, popperElement, {
const { attributes, state, styles } = usePopper(referenceElement, popperElement, {
modifiers: popperModifiers,
placement,
});
Expand Down Expand Up @@ -108,6 +108,8 @@ export const BasePortalV2: FunctionComponent<Props> = ({
}
});

const computedPlacement = state?.placement ?? placement;

return (
<Portal node={containerElement}>
<div
Expand All @@ -124,10 +126,10 @@ export const BasePortalV2: FunctionComponent<Props> = ({
<div
ref={setArrowElement}
className={classNames(arrowClassName, portalStyles.arrow, {
[portalStyles.top]: placement.indexOf('top') >= 0,
[portalStyles.bottom]: placement.indexOf('bottom') >= 0,
[portalStyles.left]: placement.indexOf('left') >= 0,
[portalStyles.right]: placement.indexOf('right') >= 0,
[portalStyles.top]: computedPlacement.indexOf('top') >= 0,
[portalStyles.bottom]: computedPlacement.indexOf('bottom') >= 0,
[portalStyles.left]: computedPlacement.indexOf('left') >= 0,
[portalStyles.right]: computedPlacement.indexOf('right') >= 0,
})}
style={styles.arrow}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ const LINK_MENU_OFFSET_MODIFIER: Modifier<'offset'> = {
},
};

const LINK_MENU_FLIP_MODIFIER: Modifier<'flip'> = {
name: 'flip',
enabled: true,
};

export function RichFormattingMenu({
availableWidth,
containerElement,
Expand Down Expand Up @@ -200,7 +205,7 @@ export function RichFormattingMenu({
return (
<TextSelectionPortalV2
containerElement={containerElement}
modifiers={[LINK_MENU_OFFSET_MODIFIER]}
modifiers={[LINK_MENU_OFFSET_MODIFIER, LINK_MENU_FLIP_MODIFIER]}
modifySelectionRect={getTextSelectionLeftTopCornerRect}
placement="bottom-start"
arrowClassName={styles.LinkMenu}
Expand Down
Loading