Skip to content

Conversation

@abinayagoudjandhyala
Copy link
Contributor

@abinayagoudjandhyala abinayagoudjandhyala commented Aug 21, 2025

Description:

This PR implements a floating “Back to Top” button that appears after the user scrolls down a certain distance (300px). When clicked, the button smoothly scrolls the page back to the top. The button improves navigation speed on long flashcard and informational pages, enhancing user experience and accessibility.

Why:

  • Allows users to effortlessly return to the top after browsing content.
  • Enhances overall UX and accessibility for keyboard users.
  • Provides a common UI feature users expect and appreciate.

Features:

  • Button is hidden by default, visible only after scrolling down >300px.
  • Smooth scroll animation on click.
  • Fixed position at bottom-right, optimized to not block content.
  • Styled with TailwindCSS to match Flash Fathom AI’s branding (purple theme).
  • Hover and focus effects for interactivity and accessibility.
  • Responsive for desktop and mobile devices.
  • Keyboard focusable with proper aria-label (aria-label="Scroll to top").

Technical Approach:

  • Added a React functional component using TypeScript.
  • Used React hooks (useState and useEffect) to track scroll position and conditionally render the button.
  • TailwindCSS used for styling consistent with site theme.

Screenshots :

Screenshot 2025-08-21 195625 Screenshot 2025-08-21 195701

This PR addresses the feature request: #86

Summary by CodeRabbit

  • New Features
    • Introduced a “Back to Top” button across pages, appearing after you scroll down and fixed at the bottom-right.
    • Smoothly scrolls the page to the top when clicked for quicker navigation.
    • Responsive behavior to avoid clutter on very small screens.
    • Includes accessible labeling for screen readers and keyboard users.

@coderabbitai
Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Introduces a new client-side BacktoTop component and integrates it into the app layout. The component listens to window scroll events to toggle a floating button’s visibility and scrolls smoothly to the top on click. The layout renders this component after the Footer and before the ToastContainer.

Changes

Cohort / File(s) Summary of Changes
Back to Top Component
src/components/BacktoTop.tsx
Added a new client-side React component that shows a floating “back to top” button based on scroll position; smooth scroll-to-top on click; includes accessibility attributes and cleanup of scroll listener.
Layout Integration
src/app/layout.tsx
Imported and rendered BacktoTop within RootLayout after Footer and before ToastContainer; no other functional changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Window
  participant BacktoTop as BacktoTop Component

  note over BacktoTop: Mount
  BacktoTop->>Window: addEventListener('scroll', onScroll)

  loop While scrolling
    User->>Window: Scroll
    Window-->>BacktoTop: scrollY change
    BacktoTop->>BacktoTop: Toggle visible if scrollY > 0.3 * innerHeight
  end

  alt Button visible
    User->>BacktoTop: Click "Back to Top"
    BacktoTop->>Window: window.scrollTo({ top: 0, behavior: 'smooth' })
  end

  note over BacktoTop: Unmount
  BacktoTop->>Window: removeEventListener('scroll', onScroll)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

A bunny blinked at the rising top,
“Hop, don’t plod—just click and pop!”
With one soft tap, the page did glide,
Up the hill in a silky slide.
Ears up high, I squeak with cheer:
Back to top is finally here! 🐇⬆️

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel
Copy link
Contributor

vercel bot commented Aug 21, 2025

@abinayagoudjandhyala is attempting to deploy a commit to the devsuraj Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
src/components/BacktoTop.tsx (6)

13-15: Initialize visibility on mount and mark the scroll listener as passive.

  • Without an initial call, the button stays hidden on reloads mid-page until the user scrolls again.
  • Passive listeners improve scroll performance.

Apply this diff:

   useEffect(() => {
     const toggleVisibility = () => {
-      setVisible(window.scrollY > window.innerHeight * 0.3);
+      setVisible(window.scrollY > 300); // or use SHOW_AFTER_PX if extracted
     };
 
-    window.addEventListener("scroll", toggleVisibility);
+    toggleVisibility(); // initialize on mount
+    window.addEventListener("scroll", toggleVisibility, { passive: true });
     return () => window.removeEventListener("scroll", toggleVisibility);
   }, []);

17-19: Respect prefers-reduced-motion for accessibility.

Users who prefer reduced motion shouldn’t get forced smooth scrolling.

Apply this diff:

   const handleScrollTop = () => {
-    window.scrollTo({ top: 0, behavior: "smooth" });
+    const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
+    window.scrollTo({ top: 0, behavior: reduceMotion ? "auto" : "smooth" });
   };

24-28: Add type=button and improve keyboard focus styles; verify mobile visibility intent.

  • type defaults to “submit” in forms; be explicit with type="button".
  • Add focus-visible ring for accessibility.
  • Current classes hide the button on mobile (hidden sm:flex). The PR states it’s responsive for desktop and mobile. If you intend to show it on mobile, drop hidden and keep flex. If hiding on mobile is intentional, update the PR description.

Apply this diff if you want the button visible on mobile and with better focus styles:

-        <button
-          onClick={handleScrollTop}
-          className="hidden sm:flex fixed cursor-pointer z-[12] right-10 bottom-16 w-12 h-12 rounded-full border-4 border-[#A557F7] bg-[#A557F7] flex items-center justify-center duration-300 hover:bg-purple-700 active:scale-90 transition"
-          aria-label="Scroll to top"
-        >
+        <button
+          type="button"
+          onClick={handleScrollTop}
+          className="flex fixed cursor-pointer z-[12] right-10 bottom-16 w-12 h-12 rounded-full border-4 border-[#A557F7] bg-[#A557F7] items-center justify-center transition duration-300 hover:bg-purple-700 active:scale-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-purple-500 dark:focus-visible:ring-offset-gray-900"
+          aria-label="Scroll to top"
+        >

29-35: Hide decorative SVG from assistive tech.

Since the button already has an aria-label, the SVG should be aria-hidden to avoid double announcements.

Apply this diff:

-          <svg
+          <svg
+            aria-hidden="true"
             className="w-4 h-4 fill-white"
             viewBox="0 0 384 512"
             xmlns="http://www.w3.org/2000/svg"
           >

21-39: Avoid unnecessary semantic wrapper; prefer a Fragment.

without a heading/landmark semantics is unnecessary here and adds extra DOM.

Apply this diff:

-    <section>
+    <>
       {visible && (
         <button
           ...
         >
           <svg ... />
         </button>
       )}
-    </section>
+    </>

5-5: Consider conventional component naming (BackToTop).

Minor naming nit: BackToTop is the more common casing. If you choose to rename, remember to update the file name and imports.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2eb7b2d and 86a5eec.

📒 Files selected for processing (2)
  • src/app/layout.tsx (2 hunks)
  • src/components/BacktoTop.tsx (1 hunks)
🔇 Additional comments (2)
src/app/layout.tsx (2)

12-12: LGTM: clean import of the client component.

Import path and naming are correct.


53-55: Placement after Footer looks right; quickly verify stacking contexts.

With z-[12], the button should sit above most content but below toast notifications (react-toastify defaults to a very high z-index). Please sanity-check that it doesn’t get obscured by any other fixed elements in your app (e.g., chat widgets, cookie banners) and that it doesn’t overlap critical UI on small screens.

Comment on lines +9 to +12
const toggleVisibility = () => {
setVisible(window.scrollY > window.innerHeight * 0.3);
};

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Align threshold with PR acceptance criteria (300px, not 30% of viewport).

Spec says “appears after the user scrolls down more than 300px,” but the code uses 0.3 × window.innerHeight, which varies across devices and may be <300px on small screens. This is a functional mismatch.

Apply this diff to match the requirement:

-      setVisible(window.scrollY > window.innerHeight * 0.3);
+      setVisible(window.scrollY > 300);

Optionally, extract the threshold for clarity and future reuse:

// near the top of the component
const SHOW_AFTER_PX = 300;
...
setVisible(window.scrollY > SHOW_AFTER_PX);
🤖 Prompt for AI Agents
In src/components/BacktoTop.tsx around lines 9 to 12, the visibility threshold
uses window.innerHeight * 0.3 which contradicts the spec requiring the button to
appear after scrolling more than 300px; replace the calculation with a fixed
300px threshold (e.g., setVisible(window.scrollY > 300)) and optionally extract
a top-level constant like SHOW_AFTER_PX = 300 for clarity and reuse, then use
that constant in the setVisible call.

@Suraj-kumar00 Suraj-kumar00 self-requested a review August 21, 2025 15:48
@Suraj-kumar00 Suraj-kumar00 self-assigned this Aug 21, 2025
@Suraj-kumar00 Suraj-kumar00 added good first issue Good for newcomers Level 1 GSSoC project Level 1 gssoc2025 GSSoC 2025 labels Aug 21, 2025
@Suraj-kumar00
Copy link
Owner

Hi @abinayagoudjandhyala,
please share this in the light mode as well.

@abinayagoudjandhyala
Copy link
Contributor Author

Screenshot 2025-08-21 213027 Screenshot 2025-08-21 213101

@Suraj-kumar00 Suraj-kumar00 merged commit 910a857 into Suraj-kumar00:main Aug 21, 2025
2 of 5 checks passed
@Suraj-kumar00
Copy link
Owner

Nice PR,
Thanks for contributing @abinayagoudjandhyala...

If can contribute to other issue please go ahead...

Copy link
Owner

@Suraj-kumar00 Suraj-kumar00 left a comment

Choose a reason for hiding this comment

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

nice

@Suraj-kumar00
Copy link
Owner

Hi @abinayagoudjandhyala,
your this PR Doesn't include the back to top in the mobile mode.

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

Labels

good first issue Good for newcomers gssoc2025 GSSoC 2025 Level 1 GSSoC project Level 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants