fix: auto-collapse pages sidebar on mobile navigation#47
Conversation
Summary by BeetleThis PR fixes a mobile UX issue where the pages sidebar remains open after navigation on mobile devices. The fix implements an auto-collapse mechanism by passing a callback function ( 📁 File Changes Summary (Consolidated across all commits):
Total Changes: 1 file changed, +6 additions, -4 deletions 🎯 Key Changes:
📊 Impact Assessment:
⚙️ SettingsSeverity Threshold: 📖 User Guide
|
| const isActive = currentSlug === `/pages/${page.slug}`; | ||
| return ( | ||
| <Link key={page.slug} href={`/pages/${page.slug}`}> | ||
| <Link onClick={onNavigate} key={page.slug} href={`/pages/${page.slug}`}> |
There was a problem hiding this comment.
The onClick={onNavigate} handler is being called without checking if onNavigate is defined. Since onNavigate is an optional prop, it could be undefined, and passing undefined to onClick may cause unexpected behavior or errors.
Confidence: 4/5
Suggested Fix
| <Link onClick={onNavigate} key={page.slug} href={`/pages/${page.slug}`}> | |
| <Link onClick={onNavigate && onNavigate} key={page.slug} href={`/pages/${page.slug}`}> | |
Alternatively, use optional chaining:
| <Link onClick={onNavigate} key={page.slug} href={`/pages/${page.slug}`}> | |
| <Link onClick={() => onNavigate?.()} key={page.slug} href={`/pages/${page.slug}`}> | |
The second approach is more idiomatic in React - it safely calls onNavigate only if it's defined, preventing potential runtime errors when the callback is not provided.
Summary by BeetleThis PR addresses a callback handling issue in the sidebar navigation component. The change modifies how the 📁 File Changes Summary (Consolidated across all commits):
Total Changes: 1 file changed, +1 additions, -1 deletions 🎯 Key Changes:
📊 Impact Assessment:
⚙️ SettingsSeverity Threshold: 📖 User Guide
|
|
✅ You're good to merge this PR! No issues found. Great job! Settings⚙️ SettingsSeverity Threshold: 📖 User Guide
|
|
Tysm for contributing! |
What does this PR do?
This PR fixes the mobile sidebar behavior on the
/pagesroute. Previously, when a user selected a page from the sidebar on mobile devices, the sidebar remained open after navigation. This change ensures the sidebar automatically collapses after a page is selected, providing a smoother and more intuitive mobile navigation experience.Closes
Type of change(s)
Checklist