-
Notifications
You must be signed in to change notification settings - Fork 524
feat(ui): add floating back-to-top button for improved navigation #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e3e64a0
a9eb243
78d234d
44c1e17
e150827
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| type ScrollToTopButtonProps = { | ||
| scrollContainerRef?: React.RefObject<HTMLElement | null>; | ||
| threshold?: number; | ||
| }; | ||
|
|
||
| export const ScrollToTopButton = ({ | ||
| scrollContainerRef, | ||
| threshold = 300, | ||
| }: ScrollToTopButtonProps) => { | ||
| const [visible, setVisible] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| const scroller = scrollContainerRef?.current || window; | ||
|
|
||
| const handleScroll = () => { | ||
| const scrollTop = | ||
| scroller instanceof Window | ||
| ? window.scrollY | ||
| : scroller.scrollTop; | ||
|
|
||
| setVisible(scrollTop > threshold); | ||
| }; | ||
|
|
||
| scroller.addEventListener('scroll', handleScroll); | ||
| return () => scroller.removeEventListener('scroll', handleScroll); | ||
| }, [scrollContainerRef, threshold]); | ||
|
Comment on lines
+14
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check initial scroll position on mount. The button visibility is only updated on scroll events. If the page is already scrolled past the threshold when the component mounts (e.g., user navigates back via browser history), the button won't appear until the user scrolls again. 🔧 Proposed fix to check initial scroll position useEffect(() => {
const scroller = scrollContainerRef?.current || window;
const handleScroll = () => {
const scrollTop =
scroller instanceof Window
? window.scrollY
: scroller.scrollTop;
setVisible(scrollTop > threshold);
};
+ // Check initial scroll position
+ handleScroll();
+
scroller.addEventListener('scroll', handleScroll);
return () => scroller.removeEventListener('scroll', handleScroll);
}, [scrollContainerRef, threshold]);🤖 Prompt for AI Agents |
||
|
|
||
| const scrollToTop = () => { | ||
| const scroller = scrollContainerRef?.current; | ||
|
|
||
| if (scroller) { | ||
| scroller.scrollTo({ top: 0, behavior: 'smooth' }); | ||
| } else { | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
| } | ||
| }; | ||
|
|
||
| if (!visible) return null; | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={scrollToTop} | ||
| aria-label="Scroll to top" | ||
| className=" | ||
| fixed top-35 right-15 z-50 | ||
| rounded-full bg-primary p-3 | ||
| text-white shadow-lg | ||
| transition-all duration-300 | ||
| hover:scale-110 hover:shadow-xl | ||
| " | ||
|
Comment on lines
+46
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result:
Sources: 🏁 Script executed: # Find Tailwind configuration in the repository
fd -e "tailwind.config" -o -e "tailwind.config.js" -o -e "tailwind.config.ts" -o -e "tailwind.config.json"Repository: AOSSIE-Org/PictoPy Length of output: 178 🏁 Script executed: # Search for any Tailwind config references
rg -i "tailwind" --type json --type js --type ts -A 5 --max-count 20Repository: AOSSIE-Org/PictoPy Length of output: 11629 🏁 Script executed: find frontend -name "tailwind.config*" -type fRepository: AOSSIE-Org/PictoPy Length of output: 44 🏁 Script executed: # Check if there's any tailwind config in frontend directory
ls -la frontend/ | grep -i tailwindRepository: AOSSIE-Org/PictoPy Length of output: 44 🏁 Script executed: # Search for any custom spacing configuration in the codebase
rg "spacing|top-35|right-15" frontend/ --type ts --type js --type json -B 2 -A 2Repository: AOSSIE-Org/PictoPy Length of output: 2063 🏁 Script executed: # Check if there's a tailwind.config file anywhere in frontend or if it's using defaults
find frontend -type f \( -name "*.config.*" -o -name "tailwind.css" -o -name "globals.css" \) | head -20Repository: AOSSIE-Org/PictoPy Length of output: 135 🏁 Script executed: # Check the App.css and index.css for any custom spacing definitions
cat frontend/src/App.css 2>/dev/null || echo "App.css not found"Repository: AOSSIE-Org/PictoPy Length of output: 7941 🏁 Script executed: # Search for CSS custom properties or theme overrides
rg "@layer|theme|--spacing|spacing:" frontend/src --type css -B 2 -A 2Repository: AOSSIE-Org/PictoPy Length of output: 1700 Use valid Tailwind v4 spacing values or arbitrary value syntax for positioning.
🤖 Prompt for AI Agents |
||
| > | ||
| ↑ | ||
| </button> | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.