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

Function scrollToCurrentHash

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

Source from the content-addressed store, hash-verified

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

Callers 1

client.tsxFile · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected