You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
635 B
16 lines
635 B
3 years ago
|
// from react-select
|
||
|
export function scrollIntoView($scrollingEl, $focusedEl) {
|
||
|
const scrollingReact = $scrollingEl.getBoundingClientRect()
|
||
|
const focusedRect = $focusedEl.getBoundingClientRect()
|
||
|
const overScroll = $focusedEl.offsetHeight / 3
|
||
|
|
||
|
if (focusedRect.bottom + overScroll > scrollingReact.bottom) {
|
||
|
$scrollingEl.scrollTop = Math.min(
|
||
|
$focusedEl.offsetTop + $focusedEl.clientHeight - $scrollingEl.offsetHeight + overScroll,
|
||
|
$scrollingEl.scrollHeight,
|
||
|
)
|
||
|
} else if (focusedRect.top - overScroll < scrollingReact.top) {
|
||
|
$scrollingEl.scrollTop = Math.max($focusedEl.offsetTop - overScroll, 0)
|
||
|
}
|
||
|
}
|