Skip to content

Add back-to-top button to blog posts - #13882

Open
manuelzzz wants to merge 2 commits into
flutter:mainfrom
manuelzzz:blog-back-to-top
Open

Add back-to-top button to blog posts#13882
manuelzzz wants to merge 2 commits into
flutter:mainfrom
manuelzzz:blog-back-to-top

Conversation

@manuelzzz

Copy link
Copy Markdown

Adds a back-to-top button to long-form blog posts to make navigation easier.

  • Back-to-top button: Adds BackToTopButton (packages/site_shared/lib/components/common/client/back_to_top_button.dart), a floating button that appears after the reader scrolls past the hero and smoothly scrolls back to the top when clicked. It reuses the existing in-content scroll-spy signal, so no additional scroll-tracking JavaScript is required.

The button is implemented as a shared site_shared component rather than directly in sites/www or sites/docs. For now, it is only wired into the blog layout, keeping it reusable for other long-form content in the future.

This is a companion to the table of contents PR (#13881). The changes are intentionally split so both PRs can be reviewed and landed independently; there is no code dependency between them.

back-to-top-preview.mov

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a floating BackToTopButton component that allows users to smoothly scroll back to the top of blog posts. The button is integrated into the BlogLayout and styled to appear when the user scrolls down. Feedback on this PR focuses on accessibility improvements, specifically recommending that the button respect user motion preferences (prefers-reduced-motion) in both the Dart scroll behavior and the SCSS transitions, as well as explicitly setting the button type to prevent accidental form submissions.

Comment thread sites/www/lib/styles/pages/_blog_page.scss
Adds BackToTopButton, a floating button shown once the reader scrolls
past the hero, that smooth-scrolls back to the top of the page on
click. Reuses the site's existing in-content scroll-spy signal, so no
new scroll-tracking JS was needed.
- Fall back to instant scrolling when the user has requested reduced
  motion, instead of always smooth-scrolling.
- Disable the button's slide-up transform/transition under
  prefers-reduced-motion: reduce.
- Set the button's type explicitly to 'button', so it can't
  accidentally submit a form if ever nested inside one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant