diff --git a/cypress/e2e/page-hash-navigation.cy.js b/cypress/e2e/page-hash-navigation.cy.js new file mode 100644 index 000000000000..efa0512dfeee --- /dev/null +++ b/cypress/e2e/page-hash-navigation.cy.js @@ -0,0 +1,16 @@ +"use strict"; + +describe("Page hash navigation", () => { + it("scrolls to the element specified by the hash", () => { + cy.visit("/guides/getting-started/#basic-setup"); + + cy.location("hash").should("eq", "#basic-setup"); + + cy.get("#basic-setup", { timeout: 10000 }) + .should("exist") + .then(($el) => { + const rect = $el[0].getBoundingClientRect(); + expect(rect.top).to.be.lessThan(200); + }); + }); +}); diff --git a/src/components/Page/Page.jsx b/src/components/Page/Page.jsx index 997b0ffae849..0dae24752e83 100644 --- a/src/components/Page/Page.jsx +++ b/src/components/Page/Page.jsx @@ -66,6 +66,7 @@ export default function Page(props) { const element = document.getElementById(hash.slice(1)); if (element) { element.scrollIntoView(); + observer.disconnect(); } }); observer.observe(target, {