Skip to content

Commit 4fe0a9f

Browse files
authored
Fix/8839 toc anchor mobile issue (#12305)
### Related Ticket(s) Closes https://jsw.ibm.com/browse/ADCMS-8839 ### Description In mobile, the ToC was not working properly. Specifically the Next Steps band. The Next Steps band has a different HTML structure and the ToC was not accounting for it, resulting in the "next steps" button when clicked, to scroll to the top of the page instead of the actual Next Steps band As for now, this is reproducible in any live page: https://www.ibm.com/products/cloud-pak-for-data/resources ### Changelog Slightly changed the way we calculate the scroll position, to account for any HTML structure. https://github.com/user-attachments/assets/bb994088-b558-4ad3-b03d-547aaedf983e
1 parent 8c1cca7 commit 4fe0a9f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/web-components/src/components/table-of-contents/table-of-contents.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,14 @@ class C4DTableOfContents extends MediaQueryMixin(
436436
const currentY = window.scrollY;
437437
let targetY;
438438

439-
if (currentY > elem.offsetTop && masthead) {
440-
targetY = elem.offsetTop - masthead.offsetHeight;
439+
const rect = elem.getBoundingClientRect();
440+
const offset = rect.top + currentY;
441+
442+
if (currentY > offset && masthead) {
443+
targetY = offset - masthead.offsetHeight;
441444
} else {
442445
targetY =
443-
elem.offsetTop -
446+
offset -
444447
parseInt(
445448
window.getComputedStyle(elem).getPropertyValue('padding-top')
446449
) -

0 commit comments

Comments
 (0)