mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
improve menu positioning
This commit is contained in:
1 parent
9b67d55f76
commit
afb849ac98
2 files changed
+11
-8
No files matched your search
@@ -122,6 +122,7 @@ export function usePosition({
|
||||
selection instanceof ColumnSelection && selection.isColSelection();
|
||||
const isRowSelection =
|
||||
selection instanceof RowSelection && selection.isRowSelection();
|
||||
let colWidth = 0;
|
||||
|
||||
if (isTableSelected(view.state)) {
|
||||
const rect = selectedRect(view.state);
|
||||
@@ -138,6 +139,7 @@ export function usePosition({
|
||||
);
|
||||
if (element instanceof HTMLElement) {
|
||||
const bounds = element.getBoundingClientRect();
|
||||
colWidth = bounds.width;
|
||||
selectionBounds.top = bounds.top - 16;
|
||||
selectionBounds.left = bounds.left;
|
||||
selectionBounds.right = bounds.right;
|
||||
@@ -200,11 +202,13 @@ export function usePosition({
|
||||
),
|
||||
Math.max(
|
||||
Math.max(offsetParent.x, margin),
|
||||
align === "center"
|
||||
? centerOfSelection - menuWidth / 2
|
||||
: align === "start"
|
||||
? selectionBounds.left
|
||||
: selectionBounds.right
|
||||
isColSelection && colWidth < 300
|
||||
? selectionBounds.right + margin
|
||||
: align === "center"
|
||||
? centerOfSelection - menuWidth / 2
|
||||
: align === "start"
|
||||
? selectionBounds.left
|
||||
: selectionBounds.right
|
||||
)
|
||||
);
|
||||
const top = Math.max(
|
||||
|
||||
@@ -49,10 +49,9 @@ const InlineMenu: React.FC<Props> = ({ items, containerRef }) => {
|
||||
|
||||
let left = position.left;
|
||||
if (menuRef.current && menuRect) {
|
||||
const spaceOnRight =
|
||||
viewportWidth - menuRef.current?.offsetWidth - position.left;
|
||||
const spaceOnRight = viewportWidth - left;
|
||||
if (spaceOnRight < menuRect.right) {
|
||||
left = position.left - spaceOnRight;
|
||||
left = left - spaceOnRight; // double the space on the right
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user