Skip to content

Commit 19d10ff

Browse files
committed
Improve scroll for taller elements
1 parent 34367c9 commit 19d10ff

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ <h2>Highlight Feature</h2>
167167
<div class="buttons">
168168
<button id="highlight-btn">Animated Highlight</button>
169169
<button id="buggy-highlight-btn">Buggy Highlight</button>
170+
<button id="off-screen-highlight-btn">Off Screen Highlight</button>
170171
<button id="simple-highlight-btn">Simple Highlight</button>
171172
<button id="transition-highlight-btn">Transition Highlight</button>
172173
<button id="disallow-close">Disallow Close</button>
@@ -923,6 +924,18 @@ <h2>Usage and Demo</h2>
923924
});
924925
});
925926

927+
document.getElementById("off-screen-highlight-btn").addEventListener("click", () => {
928+
driver().highlight({
929+
element: ".container",
930+
popover: {
931+
title: "Buggy Highlight",
932+
description: "Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
933+
side: "bottom",
934+
align: "start",
935+
},
936+
});
937+
});
938+
926939
document.getElementById("highlight-btn").addEventListener("click", () => {
927940
driver({
928941
animate: true,

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ export function bringInView(element: Element) {
3030

3131
const shouldSmoothScroll = getConfig("smoothScroll");
3232

33+
const isTallerThanViewport = (element as HTMLElement).offsetHeight > window.innerHeight;
34+
3335
element.scrollIntoView({
3436
// Removing the smooth scrolling for elements which exist inside the scrollable parent
3537
// This was causing the highlight to not properly render
3638
behavior: !shouldSmoothScroll || hasScrollableParent(element) ? "auto" : "smooth",
3739
inline: "center",
38-
block: "center",
40+
block: isTallerThanViewport ? "start" : "center",
3941
});
4042
}
4143

0 commit comments

Comments
 (0)