Skip to content

Commit 7fd28c3

Browse files
fix: improve mobile positioning for link dialog in form builder checkbox editor (calcom#24268)
* Updated positionEditorElement function to respect viewport boundaries * cleanup
1 parent ff17aa7 commit 7fd28c3

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

packages/ui/components/editor/plugins/ToolbarPlugin.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,31 @@ function positionEditorElement(editor: HTMLInputElement, rect: DOMRect | null) {
5454
editor.style.left = "-1000px";
5555
} else {
5656
editor.style.opacity = "1";
57-
editor.style.top = `${rect.top + rect.height + window.pageYOffset + 10}px`;
58-
editor.style.left = `${rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2}px`;
57+
58+
let top = rect.top + rect.height + window.pageYOffset + 10;
59+
let left = rect.left + window.pageXOffset - editor.offsetWidth / 2 + rect.width / 2;
60+
61+
const viewportWidth = window.innerWidth;
62+
const viewportHeight = window.innerHeight;
63+
const editorWidth = editor.offsetWidth || 300;
64+
const editorHeight = editor.offsetHeight || 100;
65+
66+
if (left < 10) {
67+
left = 10;
68+
} else if (left + editorWidth > viewportWidth - 10) {
69+
left = viewportWidth - editorWidth - 10;
70+
}
71+
72+
if (top + editorHeight > window.pageYOffset + viewportHeight - 10) {
73+
top = rect.top + window.pageYOffset - editorHeight - 10;
74+
75+
if (top < window.pageYOffset + 10) {
76+
top = window.pageYOffset + 10;
77+
}
78+
}
79+
80+
editor.style.top = `${top}px`;
81+
editor.style.left = `${left}px`;
5982
}
6083
}
6184

packages/ui/components/editor/stylesEditor.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pre::-webkit-scrollbar-thumb {
276276
top: -10000px;
277277
left: -10000px;
278278
margin-top: -6px;
279-
max-width: 300px;
279+
max-width: min(300px, calc(100vw - 20px));
280280
width: 100%;
281281
opacity: 0;
282282
background-color: #fff;

0 commit comments

Comments
 (0)