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

Function updateToc

packages/dev/docs/src/attachToToC.js:24–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 }
23
24 function updateToc() {
25 requestAnimationFrame(() => {
26 // this needs to be improved a little but the math hurts my head right now
27 // right now it's impossible to select the last section if the last two heights combined are smaller than the viewport height
28 headers.some((header, i) => {
29 if (
30 header.header.offsetTop + header.header.getBoundingClientRect().height >
31 document.documentElement.scrollTop
32 ) {
33 let currentSelection = document.querySelectorAll(`#toc .${sideNavStyles['is-selected']}`);
34 if (currentSelection) {
35 currentSelection.forEach(node => {
36 node.classList.remove(sideNavStyles['is-selected']);
37 const link = node.querySelector('[aria-current]');
38 if (link) {
39 link.removeAttribute('aria-current');
40 }
41 });
42 }
43 header.link.parentElement.classList.add(sideNavStyles['is-selected']);
44 header.link.setAttribute('aria-current', 'location');
45 return true;
46 }
47 });
48 });
49 }
50
51 updateToc();
52

Callers 1

attachToToCFunction · 0.85

Calls 4

removeAttributeMethod · 0.80
setAttributeMethod · 0.80
removeMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected