Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
22 lines
721 B
TypeScript
22 lines
721 B
TypeScript
/**
|
|
* Scrolls `target` into view inside `container` by adjusting `container.scrollTop` only.
|
|
* Avoids `Element.scrollIntoView`, which on mobile can shift `visualViewport.offsetTop`
|
|
* and punch holes through fixed modal backdrops.
|
|
*/
|
|
export const scrollElementIntoContainer = (container: HTMLElement, target: HTMLElement) => {
|
|
const containerRect = container.getBoundingClientRect()
|
|
const targetRect = target.getBoundingClientRect()
|
|
const overflowBottom = targetRect.bottom - containerRect.bottom
|
|
const overflowTop = containerRect.top - targetRect.top
|
|
|
|
if (overflowBottom > 0) {
|
|
container.scrollTop += overflowBottom
|
|
|
|
return
|
|
}
|
|
|
|
if (overflowTop > 0) {
|
|
container.scrollTop -= overflowTop
|
|
}
|
|
}
|