MCPcopy Create free account
hub / github.com/code-forge-io/react-router-devtools / scrollIntoView

Function scrollIntoView

docs/app/utils/scroll-into-view.ts:1–21  ·  view source on GitHub ↗
(e: React.MouseEvent, id: string, offset = -80, behavior: ScrollBehavior = "smooth")

Source from the content-addressed store, hash-verified

1export function scrollIntoView(e: React.MouseEvent, id: string, offset = -80, behavior: ScrollBehavior = "smooth") {
2 e.preventDefault()
3
4 const element = document.getElementById(id)
5 if (!element) return Promise.resolve()
6
7 const targetY = element.getBoundingClientRect().top + window.scrollY + offset
8
9 window.scrollTo({ top: targetY, behavior })
10
11 if (behavior !== "smooth") {
12 return Promise.resolve()
13 }
14
15 const distance = Math.abs(window.scrollY - targetY)
16 const duration = Math.min(distance / 2, 1000)
17
18 return new Promise((resolve) => {
19 setTimeout(resolve, duration)
20 })
21}

Callers 1

handleItemClickFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…