-
Notifications
You must be signed in to change notification settings - Fork 26
feat(ui): Implement responsive 'Show More/Less' toggle for features s… #77
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useState, useEffect } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const useIsMobile = (breakpoint = 768) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isMobile, setIsMobile] = useState( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof window !== 'undefined' ? window.innerWidth < breakpoint : false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const checkMobile = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsMobile(window.innerWidth < breakpoint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.addEventListener('resize', checkMobile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkMobile(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return () => window.removeEventListener('resize', checkMobile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [breakpoint]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+17
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. Add debounce/throttle to the resize event listener. The resize event can fire 100+ times per second during active window resizing, causing excessive state updates and re-renders. This degrades performance, especially on lower-end mobile devices. Apply this diff to add a debounced resize handler: useEffect(() => {
+ let timeoutId: NodeJS.Timeout;
+
const checkMobile = () => {
- setIsMobile(window.innerWidth < breakpoint);
+ clearTimeout(timeoutId);
+ timeoutId = setTimeout(() => {
+ setIsMobile(window.innerWidth < breakpoint);
+ }, 150);
};
window.addEventListener('resize', checkMobile);
- checkMobile();
+ // Initial check without debounce
+ setIsMobile(window.innerWidth < breakpoint);
- return () => window.removeEventListener('resize', checkMobile);
+ return () => {
+ window.removeEventListener('resize', checkMobile);
+ clearTimeout(timeoutId);
+ };
}, [breakpoint]);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return isMobile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default useIsMobile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add accessibility attributes to the toggle button.
The toggle button is missing ARIA attributes that are essential for screen reader users to understand the button's purpose and state.
Apply this diff to add proper accessibility:
{requiresToggle && ( <div className="flex justify-center mt-8 md:hidden"> <button onClick={handleToggle} + aria-expanded={isExpanded} + aria-controls="features-grid" + aria-label={isExpanded ? 'Show fewer features' : 'Show more features'} className="py-2 px-6 text-sm font-semibold rounded-lg bg-primary-600 text-white hover:bg-primary-700 transition-colors duration-300" > {isExpanded ? 'Show Less Features' : 'Show More Features'} </button> </div> )}Also add the corresponding
idto the features grid:📝 Committable suggestion
🤖 Prompt for AI Agents