InPactAI icon indicating copy to clipboard operation
InPactAI copied to clipboard

feat: add scroll to top button with progress indicator

Open Swaim-Sahay opened this issue 1 year ago β€’ 2 comments

Closes #204

πŸš€ Added Scroll to Top Button

πŸ“ Description

Implemented an enhanced scroll-to-top button with smooth animations and visual progress indicator to improve user navigation experience.

🎯 Changes Made

  • Created ScrollToTop component at Frontend/src/components/ui/scroll-to-top.tsx
  • Integrated component into App.tsx
  • Implemented on branch feature/scroll-to-top

✨ Features

  • Auto-appears after scrolling 300px down
  • Circular progress ring indicating scroll position
  • Gradient purple/indigo background matching brand colors
  • Smooth scroll animation to top
  • Hover tooltip "Back to top"
  • Fade in/out transitions
  • Bounce animation on hover

πŸ›  Technical Implementation

  • Framework: React 19 + TypeScript
  • Styling: Tailwind CSS with custom gradients
  • Icons: Lucide React (ArrowUp)
  • Performance: requestAnimationFrame throttling for scroll events
  • Accessibility: WCAG 2.1 compliant with proper ARIA attributes

πŸ§ͺ Testing

  • βœ… Chrome, Firefox, Safari compatibility verified
  • βœ… Mobile responsive (tested on iOS/Android)
  • βœ… No performance degradation during scroll
  • βœ… Accessibility validated (keyboard navigation, screen readers)
  • βœ… No console errors or warnings

πŸ“Έ Preview

https://github.com/user-attachments/assets/e9d7c766-7691-4962-b1e2-417d99df36e2

βœ… Checklist

  • [x] Follows project code style guidelines
  • [x] No console errors or warnings
  • [x] Component is reusable and maintainable
  • [x] Meets accessibility standards (ARIA labels, focus states)
  • [x] Performance optimized (passive listeners, RAF throttling)
  • [x] Cross-browser compatible
  • [x] Mobile responsive
  • [x] TypeScript types properly defined

πŸ“¦ Files Changed

  • Frontend/src/components/ui/scroll-to-top.tsx (new)
  • Frontend/src/App.tsx (modified)

Summary by CodeRabbit

  • New Features
    • Added a floating scroll-to-top control that appears after scrolling, shows scroll progress with a circular indicator, and smoothly returns you to the top when clicked. Includes animated visuals, hover tooltip, and responsive sizing.
    • Integrated the control globally so it works automatically across route changes.

✏️ Tip: You can customize this high-level summary in your review settings.

Swaim-Sahay avatar Nov 22 '25 11:11 Swaim-Sahay

Walkthrough

A ScrollToTop React component was added and mounted in App.tsx inside the AuthProvider/Router tree. It shows a floating button after 300px scroll, renders a circular progress ring reflecting page scroll percentage, and smooth-scrolls to top when clicked.

Changes

Cohort / File(s) Summary
New Scroll-To-Top Component
Frontend/src/components/ui/scroll-to-top.tsx
Adds a React component that: tracks scroll position (visible after 300px), computes scroll progress, updates via requestAnimationFrame, renders a circular SVG progress ring with gradient/button UI and hover tooltip, and scrolls to top smoothly on click. Cleans up listeners/animation frame on unmount.
App Integration
Frontend/src/App.tsx
Imports and renders ScrollToTop within the AuthProvider/Router tree to enable global scroll-to-top behavior across routes.

Sequence Diagram(s)

sequenceDiagram
    participant U as User (browser)
    participant C as ScrollToTop Component
    participant W as Window (scroll/resize)

    Note over U,C: Page loads
    U->>C: mount()
    C->>W: addEventListener(scroll)
    C->>W: addEventListener(resize)
    Note right of W: On scroll (debounced via requestAnimationFrame)
    W-->>C: scroll event
    C->>C: compute isVisible & scrollProgress
    C-->>U: update UI (show/hide, ring offset)

    alt User clicks button
        U->>C: click()
        C->>W: window.scrollTo({ top:0, behavior:"smooth" })
        Note over W,C: smooth scroll animates back to top
    end

    Note over C: on unmount -> remove listeners, cancel RAF

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to event listener lifecycle and RAF cancellation in Frontend/src/components/ui/scroll-to-top.tsx.
  • Verify scroll progress calculation across short and long pages and correct SVG dash-offset mapping.
  • Check keyboard accessibility and ARIA attributes on the button.
  • Confirm styling (Tailwind classes/gradients) matches existing design tokens if required.

Poem

πŸ‡βœ¨ I hopped in code with ears held high,
A glowing ring to mark the sky,
When pages stretch and journeys long,
I sing a tiny carrot songβ€”
Tap my paw and up you fly!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately describes the main change: adding a scroll-to-top button with a progress indicator component.
Linked Issues check βœ… Passed The pull request implements all primary objectives from issue #204: scroll-to-top button appearing after 300px, circular progress ring, gradient purple/indigo design, smooth animation, tooltip, keyboard/ARIA support, and React hooks with RAF optimization.
Out of Scope Changes check βœ… Passed All changes are within scope: new ScrollToTop component file and App.tsx integration to implement the scroll-to-top feature requested in issue #204.
✨ Finishing touches
  • [ ] πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • [ ] 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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 22 '25 11:11 coderabbitai[bot]

Hi @chandansgowda

Raised a PR here here #205 .Please review and let me know if any further changes required. Thank you.

Swaim-Sahay avatar Nov 26 '25 18:11 Swaim-Sahay