fix(NavItem): close managed sidebar on mobile item click#12259
fix(NavItem): close managed sidebar on mobile item click#12259fallmo wants to merge 3 commits intopatternfly:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughNavItem replaces Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/react-core/src/components/Nav/NavItem.tsx`:
- Line 199: The call to context.onSelect in NavItem is unsafe because
NavContextProps.onSelect is optional; update the NavItem component to check for
existence before invoking it (e.g., if (context.onSelect)
context.onSelect(event, groupId, itemId, to, preventLinkDefault, onClick)) so
that context.onSelect is only called when defined; locate the invocation of
context.onSelect in NavItem.tsx and wrap it with a presence check or optional
chaining to avoid runtime errors.
- Around line 201-203: The sidebar auto-close is triggered for flyout parent
items because the handler calls onSidebarToggle when isManagedSidebar &&
isMobile && isSidebarOpen; update that conditional to skip calling
onSidebarToggle for flyout parents by adding a check for !hasFlyout (or
equivalent prop) so that when hasFlyout is true (Component renders as button)
the sidebar does not auto-close; adjust the conditional around onSidebarToggle
in NavItem (referencing isManagedSidebar, isMobile, isSidebarOpen, hasFlyout,
onSidebarToggle, and Component) to only call onSidebarToggle when hasFlyout is
false.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8a66f0e4-8469-45f3-b3a3-360ef59211bd
📒 Files selected for processing (1)
packages/react-core/src/components/Nav/NavItem.tsx
…idebar toggle condition
|
Preview: https://pf-react-pr-12259.surge.sh A11y report: https://pf-react-pr-12259-a11y.surge.sh |
What:
Close a managed Page sidebar on mobile when a nav item is clicked.
Why:
When the viewport width is below the desktop breakpoint, selecting a navigation item should automatically close the sidebar to reveal the main content area. (Ref patternfly/patternfly#8161)
Changes:
PageContextinto theNavItemcomponent.onSidebarTogglewhenisManagedSidebar,isMobile, andisSidebarOpenare all true.context: NavContextPropsinstead ofcontext: any.Summary by CodeRabbit
Bug Fixes
Refactor