Skip to content

armgit / vaul

Public Imported from GitHub
0

A drawer component for React.

Scroll into view only when needed

emilkowalski1d7bef2d6cd0
diff --git a/src/use-prevent-scroll.ts b/src/use-prevent-scroll.ts
index c1695da..c6108f4 100644
--- a/src/use-prevent-scroll.ts
+++ b/src/use-prevent-scroll.ts
@@ -303,7 +303,9 @@ function scrollIntoView(target: Element) {
if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
let scrollableTop = scrollable.getBoundingClientRect().top;
let targetTop = target.getBoundingClientRect().top;
- if (targetTop > scrollableTop + target.clientHeight) {
+ const keyboardHeight = scrollable.getBoundingClientRect().bottom;
+
+ if (targetTop > keyboardHeight) {
scrollable.scrollTop += targetTop - scrollableTop;
}
}