Add back-to-top button to blog posts - #13882
Conversation
There was a problem hiding this comment.
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.
957dc5d to
0574eac
Compare
|
/gcbrun |
|
Staged preview of the updated docs.flutter.dev site (updated for commit 0574eac): https://flutter-docs-prod--docs-pr13882-blog-back-to-top-yn6vncjk.web.app |
|
Staged preview of the updated flutter.dev site (updated for commit 0574eac): https://flutter-dev-230821--www-pr13882-blog-back-to-top-gcad24w2.web.app |
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.
0574eac to
d2850f8
Compare
Adds a back-to-top button to long-form blog posts to make navigation easier.
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 existingin-contentscroll-spy signal, so no additional scroll-tracking JavaScript is required.The button is implemented as a shared
site_sharedcomponent rather than directly insites/wwworsites/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