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 5b67b85): https://flutter-docs-prod--docs-pr13882-blog-back-to-top-yn6vncjk.web.app |
|
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 |
0574eac to
d2850f8
Compare
parlough
left a comment
There was a problem hiding this comment.
Thanks for splitting this up! Mostly looks great, just two questions/suggestions around behavior for keyboard users:
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.
d2850f8 to
8379121
Compare
- 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.
|
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? |
parlough
left a comment
There was a problem hiding this comment.
Thanks for making those adjustments! Looks good to me.
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. |
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