Skip to content

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

Merged
parlough merged 5 commits into
flutter:mainfrom
manuelzzz:blog-back-to-top
Sep 16, 2026
Merged

parlough merged 5 commits into
flutter:mainfrom
manuelzzz:blog-back-to-top

Conversation

@manuelzzz

Copy link
Copy Markdown
Contributor

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
@parlough

Copy link
Copy Markdown
Member

/gcbrun

@flutter-website-bot

flutter-website-bot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit 5b67b85):

https://flutter-docs-prod--docs-pr13882-blog-back-to-top-yn6vncjk.web.app

@flutter-website-bot

flutter-website-bot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit 5b67b85):

https://flutter-dev-230821--www-pr13882-blog-back-to-top-gcad24w2.web.app

@parlough parlough left a comment

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.

Thanks for splitting this up! Mostly looks great, just two questions/suggestions around behavior for keyboard users:

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.
manuelzzz and others added 2 commits September 15, 2026 00:36
- Hide the back-to-top button from the accessibility tree (visibility:
  hidden) until it becomes visible, instead of relying on opacity/
  pointer-events alone.
- Move focus to the page title on click so keyboard users don't lose
  focus after scrolling to the top.
@manuelzzz

Copy link
Copy Markdown
Contributor Author

All the requested changes have been made.

I was also thinking about opening an issue to turn this component into a more global one. I think a bunch of other pages could benefit from having this available as a shared component.

It might be a somewhat larger feature, but I'd be happy to work on it and, if needed, discuss the best approach for implementing it.

What do you think about this, @parlough?

@manuelzzz
manuelzzz requested a review from parlough September 15, 2026 04:02

@parlough parlough left a comment

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.

Thanks for making those adjustments! Looks good to me.

@parlough

Copy link
Copy Markdown
Member

I was also thinking about opening an issue to turn this component into a more global one. I think a bunch of other pages could benefit from having this available as a shared component.

It might be a somewhat larger feature, but I'd be happy to work on it and, if needed, discuss the best approach for implementing it.

I can see it being a valuable addition on longer docs pages. If you're interested, feel free to open an issue with your thoughts and we can see what others think.

@parlough
parlough merged commit de36db7 into flutter:main Sep 16, 2026
15 checks passed
@manuelzzz
manuelzzz deleted the blog-back-to-top branch September 16, 2026 14:53
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.

3 participants