Skip to content

Fix go to top [Fixes #15412]#15439

Merged
wackerow merged 3 commits into
ethereum:devfrom
smithrashell:fix/go-to-top-button
May 17, 2025
Merged

Fix go to top [Fixes #15412]#15439
wackerow merged 3 commits into
ethereum:devfrom
smithrashell:fix/go-to-top-button

Conversation

@smithrashell
Copy link
Copy Markdown
Contributor

Description

The "Go to top" button was not functioning due to a missing anchor target.

This PR:

  • Adds an id="top" to the main container in BaseLayout.tsx
  • Updates the href used by the "Go to top" button in Footer.tsx to point to #top

Related Issue

Fixes #15412

@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2025

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit aafe223
🔍 Latest deploy log https://app.netlify.com/projects/ethereumorg/deploys/6828ce5831c9e8000835da2b
😎 Deploy Preview https://deploy-preview-15439--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 46 (🔴 down 11 from production)
Accessibility: 95 (🟢 up 1 from production)
Best Practices: 91 (🔴 down 5 from production)
SEO: 98 (no change from production)
PWA: 59 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @smithrashell! Thanks for the fix! This does work, but I think we can take it another step to make sure we don't break any html rules, and simplify the need to add id's.

Let me know if you have issues!

Comment thread src/layouts/BaseLayout.tsx Outdated
*/}
<SkipLink />
<div className="mx-auto max-w-screen-2xl">
<div className="mx-auto max-w-screen-2xl" id="top">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to be a little careful here since this same id is already being used on some pages, such as the Docs pages, and this would result in them being duplicated which isn't valid HTML.. I think we can do this another way.

Comment thread src/components/Footer.tsx Outdated
variant="outline"
isSecondary
onClick={() => scrollIntoView("__next")}
onClick={() => scrollIntoView("top")}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function currently accepts an id (toId), but we could broaden it's usage by refactoring to use a css selector string with querySelector

I would just update scrollIntoView to accept a query selector instead of an id, and then we can just target the h1 in this case, and update any other instances passing an id to prefix a #

For example:

// src/lib/utils/scrollIntoView.ts

export const scrollIntoView = (
  selector: string,
  options: ScrollIntoViewOptions = { behavior: "smooth", block: "start" }
): void => {
  const element = document.querySelector(selector)

  if (!element) return

  element.scrollIntoView(options)
}

Then this line becomes

Suggested change
onClick={() => scrollIntoView("top")}
onClick={() => scrollIntoView("h1")}

And I believe the only other place we use this is in Button, where we can prefix the id with #:

// src/components/ui/buttons/Button.tsx:108

      toId && scrollIntoView("#" + toId)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wackerow , Thanks for the clear feedback! I've updated the implementation as suggested and just pushed the changes. Let me know if anything else needs adjustment.

@github-actions github-actions Bot added the tooling 🔧 Changes related to tooling of the project label May 16, 2025
Comment thread src/components/Footer.tsx Outdated
Copy link
Copy Markdown
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks so much @smithrashell... working great for me, pulling in!

@wackerow wackerow merged commit f19858b into ethereum:dev May 17, 2025
5 of 6 checks passed
@gitpoap-bot
Copy link
Copy Markdown

gitpoap-bot Bot commented May 17, 2025

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2025 Ethereum.org Contributor:

GitPOAP: 2025 Ethereum.org Contributor GitPOAP Badge

Join the [ethereum.org Discord server](https://ethereum.org/discord) to explore more ways to contribute to the project. Depending on the tasks you complete, you may also unlock additional rewards. Visit [ethereum.org/contributing](https://ethereum.org/contributing) to learn more.

Head to gitpoap.io & connect your GitHub account to mint!Keep buidling, keep learning, and let's grow the Ethereum open-source community together 🌱

Learn more about GitPOAPs here.

@wackerow
Copy link
Copy Markdown
Member

@all-contributors please add @smithrashell for bug fix

@allcontributors
Copy link
Copy Markdown
Contributor

@wackerow

I've put up a pull request to add @smithrashell! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tooling 🔧 Changes related to tooling of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go to top button npt working

2 participants