diff --git a/scm-ui/ui-components/src/useScrollToElement.ts b/scm-ui/ui-components/src/useScrollToElement.ts index 0e00b679e2..c68c632835 100644 --- a/scm-ui/ui-components/src/useScrollToElement.ts +++ b/scm-ui/ui-components/src/useScrollToElement.ts @@ -39,7 +39,7 @@ const useScrollToElement = ( clearInterval(intervalId); } else { tries++; - const element = contentRef.querySelector(CSS.escape(elementSelector)); + const element = contentRef.querySelector(escapeIdStartingWithNumber(elementSelector)); if (element) { const headerElement = document.querySelector(".navbar-brand"); const margin = headerElement ? headerElement.getBoundingClientRect().height : 45; @@ -57,4 +57,12 @@ const useScrollToElement = ( }, [contentRef, ...dependencies]); }; +function escapeIdStartingWithNumber(selector: string) { + if (selector.startsWith("#")) { + return `#${CSS.escape(selector.substring(1))}`; + } + + return selector; +} + export default useScrollToElement;