Skip to content

Commit fbb0ea3

Browse files
committed
fix: share query modal window now gets enough space and proper placement
1 parent 0f8e834 commit fbb0ea3

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/yasqe/src/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ export class Yasqe extends CodeMirror {
467467
urlBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
468468
buttonContainer.appendChild(urlBtn);
469469
urlBtn.onclick = async () => {
470+
if (!this.config.createShareableLink) return;
470471
const url = this.config.createShareableLink(this);
471472
await copyToClipboard(url, "URL");
472473
};
@@ -482,6 +483,7 @@ export class Yasqe extends CodeMirror {
482483
shortenBtn.disabled = true;
483484
shortenBtn.innerText = "Shortening...";
484485
try {
486+
if (!this.config.createShareableLink) return;
485487
const longUrl = this.config.createShareableLink(this);
486488
const shortUrl = await createShortLink(this, longUrl);
487489
await copyToClipboard(shortUrl, "Shortened URL");
@@ -537,9 +539,25 @@ export class Yasqe extends CodeMirror {
537539
// Position popup after layout is complete
538540
const positionPopup = () => {
539541
if (!popup) return;
540-
const sharePos = shareLinkWrapper.getBoundingClientRect();
541-
popup.style.top = shareLinkWrapper.offsetTop + sharePos.height + "px";
542-
popup.style.left = shareLinkWrapper.offsetLeft + shareLinkWrapper.clientWidth - popup.clientWidth + "px";
542+
const buttonsRect = buttons.getBoundingClientRect();
543+
const popupHeight = popup.offsetHeight || 300; // Estimated height
544+
const viewportHeight = window.innerHeight;
545+
const spaceAbove = buttonsRect.top;
546+
const spaceBelow = viewportHeight - buttonsRect.bottom;
547+
548+
// If there's enough space above (with some padding), position above
549+
// Otherwise position below (will use scrolling if needed)
550+
if (spaceAbove >= popupHeight + 20) {
551+
popup.style.bottom = (buttons.clientHeight || 46) + "px";
552+
popup.style.top = "auto";
553+
popup.style.right = "0px";
554+
} else {
555+
// Not enough space above, use fixed positioning at top of viewport
556+
popup.style.position = "fixed";
557+
popup.style.bottom = "auto";
558+
popup.style.top = "20px";
559+
popup.style.right = "20px";
560+
}
543561
};
544562

545563
if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {

packages/yasqe/src/scss/buttons.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@
103103
width: auto;
104104
min-width: 300px;
105105
max-width: 400px;
106+
max-height: calc(100vh - 100px);
107+
overflow-y: auto;
106108
height: auto;
107109
display: flex;
108110
flex-direction: column;
109111
gap: 8px;
112+
z-index: 10001;
110113

111114
.yasqe_sharePopup_title {
112115
font-weight: 600;

0 commit comments

Comments
 (0)