diff --git a/gradle/changelog/mind_header_when_scrolling.yaml b/gradle/changelog/mind_header_when_scrolling.yaml new file mode 100644 index 0000000000..1de338996b --- /dev/null +++ b/gradle/changelog/mind_header_when_scrolling.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: The height of the navigation bar is now considered when scrolling to an element via anchor diff --git a/scm-ui/ui-components/src/useScrollToElement.ts b/scm-ui/ui-components/src/useScrollToElement.ts index 778a69d88b..125f9c2990 100644 --- a/scm-ui/ui-components/src/useScrollToElement.ts +++ b/scm-ui/ui-components/src/useScrollToElement.ts @@ -40,9 +40,12 @@ const useScrollToElement = ( } else { tries++; const element = contentRef.querySelector(elementSelector); - if (element && element.scrollIntoView) { + if (element) { + const headerElement = document.querySelector(".navbar-brand"); + const margin = headerElement ? headerElement.getBoundingClientRect().height : 45; clearInterval(intervalId); - element.scrollIntoView(); + const y = element.getBoundingClientRect().top + window.pageYOffset - margin; + window.scrollTo({top: y}); } } }, 200);