feat(sidebar): controlled support for Sidebar.Group#807
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR adds controlled state management to collapsible sidebar groups. The Sidebar.Group component now accepts Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
🧹 Nitpick comments (1)
packages/raystack/components/sidebar/sidebar-misc.tsx (1)
86-94: 💤 Low valueConsider optimizing internal state update for fully controlled mode.
When the component is fully controlled (i.e.,
providedOpen !== undefined), line 90 still updatesinternalOpen, even though this state is not used (line 84 gives precedence toprovidedOpen). While harmless, you could optimize this by conditionally updating internal state only when uncontrolled:♻️ Optional optimization
const handleOpenChange = useCallback( (value: unknown[]) => { if (isCollapsed) return; const nextOpen = value.length > 0; - setInternalOpen(nextOpen); + if (providedOpen === undefined) { + setInternalOpen(nextOpen); + } onOpenChange?.(nextOpen); }, - [isCollapsed, onOpenChange] + [isCollapsed, providedOpen, onOpenChange] );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/raystack/components/sidebar/sidebar-misc.tsx` around lines 86 - 94, handleOpenChange currently always calls setInternalOpen even when the component is fully controlled via providedOpen; update the handler to only update internalOpen (via setInternalOpen) when providedOpen is undefined (i.e., uncontrolled) while still calling onOpenChange and respecting isCollapsed; locate handleOpenChange and add a conditional guard around setInternalOpen that checks providedOpen before updating internal state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/raystack/components/sidebar/sidebar-misc.tsx`:
- Around line 86-94: handleOpenChange currently always calls setInternalOpen
even when the component is fully controlled via providedOpen; update the handler
to only update internalOpen (via setInternalOpen) when providedOpen is undefined
(i.e., uncontrolled) while still calling onOpenChange and respecting
isCollapsed; locate handleOpenChange and add a conditional guard around
setInternalOpen that checks providedOpen before updating internal state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ba01ced7-783c-40de-923a-5d93714b22cf
📒 Files selected for processing (6)
apps/www/src/components/docs/sidebar.tsxapps/www/src/content/docs/components/sidebar/demo.tsapps/www/src/content/docs/components/sidebar/index.mdxapps/www/src/content/docs/components/sidebar/props.tspackages/raystack/components/sidebar/__tests__/sidebar.test.tsxpackages/raystack/components/sidebar/sidebar-misc.tsx
Summary
open,defaultOpen, andonOpenChangeprops toSidebar.Groupso consumers can drive a collapsible group's expanded state externally, mirroring the existingSidebarRootAPI.key-based remount trick on the Base UI accordion with a controlledvalue/onValueChange, while still forcing the panel open when the parent sidebar is collapsed (preserving existing behavior).valueprop on the group — the accordion now uses a single sentinel item value internally since each group has exactly one accordion item.SidebarGroupPropsand added a "Controlled Group" example to the docs.defaultOpen={false}, fully controlledopen/onOpenChange, and uncontrolled toggle dispatch.