
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1792 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
19 lines
367 B
TypeScript
19 lines
367 B
TypeScript
export function scrollIntoView(el: HTMLElement | null | undefined) {
|
|
if (!el) {
|
|
return
|
|
}
|
|
|
|
const boundingRect = el.getBoundingClientRect()
|
|
const scrollY = window.scrollY
|
|
|
|
if (
|
|
boundingRect.top > (scrollY + window.innerHeight) ||
|
|
boundingRect.top < scrollY
|
|
) {
|
|
el.scrollIntoView({
|
|
behavior: 'smooth',
|
|
block: 'center',
|
|
inline: 'nearest',
|
|
})
|
|
}
|
|
} |