MCPcopy Create free account
hub / github.com/adobe/react-spectrum / scrollToCurrentHash

Function scrollToCurrentHash

packages/dev/s2-docs/src/client.tsx:341–363  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

339window.addEventListener('scroll', onScroll, {passive: true, capture: true});
340
341function scrollToCurrentHash() {
342 if (!location.hash || location.hash === '#') {
343 return;
344 }
345
346 let anchorId = location.hash.slice(1);
347 try {
348 anchorId = decodeURIComponent(anchorId);
349 } catch {
350 // Fall back to raw hash
351 }
352
353 if (!anchorId) {
354 return;
355 }
356
357 requestAnimationFrame(() => {
358 let element = document.getElementById(anchorId);
359 if (element) {
360 element.scrollIntoView();
361 }
362 });
363}
364
365if (document.readyState === 'complete' || document.readyState === 'interactive') {
366 scrollToCurrentHash();

Callers 1

client.tsxFile · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected