MCPcopy
hub / github.com/JedWatson/react-select / scrollIntoView

Function scrollIntoView

packages/react-select/src/utils.ts:264–286  ·  view source on GitHub ↗
(
  menuEl: HTMLElement,
  focusedEl: HTMLElement
)

Source from the content-addressed store, hash-verified

262// ------------------------------
263
264export function scrollIntoView(
265 menuEl: HTMLElement,
266 focusedEl: HTMLElement
267): void {
268 const menuRect = menuEl.getBoundingClientRect();
269 const focusedRect = focusedEl.getBoundingClientRect();
270 const overScroll = focusedEl.offsetHeight / 3;
271
272 if (focusedRect.bottom + overScroll > menuRect.bottom) {
273 scrollTo(
274 menuEl,
275 Math.min(
276 focusedEl.offsetTop +
277 focusedEl.clientHeight -
278 menuEl.offsetHeight +
279 overScroll,
280 menuEl.scrollHeight
281 )
282 );
283 } else if (focusedRect.top - overScroll < menuRect.top) {
284 scrollTo(menuEl, Math.max(focusedEl.offsetTop - overScroll, 0));
285 }
286}
287
288// ==============================
289// Get bounding client object

Callers 2

componentDidMountMethod · 0.90
componentDidUpdateMethod · 0.90

Calls 1

scrollToFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…