feat: Introduce SidebarItem component to manage sidebar entry colla…#8150
feat: Introduce SidebarItem component to manage sidebar entry colla…#8150JayadityaGit wants to merge 1 commit intoreactjs:mainfrom
SidebarItem component to manage sidebar entry colla…#8150Conversation
…pse/expand state and add `onClick` prop to `SidebarLink`.
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 Five Pages Changed SizeThe following pages changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this. |
clideo_editor_b3a727c65cf5481b997119fdab88f23b.mp4
Overview
This PR enhances the React documentation website's sidebar navigation by allowing users to toggle dropdowns when clicking an already-selected item. This improves overall navigation usability and aligns the behavior with common UI expectations.
Problem Statement
Previously, clicking on an active/selected sidebar item that had a dropdown produced no action.
Users naturally expect that clicking the same selected item again should collapse the dropdown—similar to accordion-style navigation patterns.
This mismatch resulted in:
Solution
A toggle mechanism has been implemented to allow collapsing an expanded dropdown by clicking the currently selected item a second time.
Technical Changes
Modified Files
src/components/Layout/Sidebar/SidebarLink.tsxonClickprop to support custom click behavioronClickhandler down to the underlyingLinkcomponentsrc/components/Layout/Sidebar/SidebarRouteTree.tsxuseStateanduseEffectSidebarItemcomponent to encapsulate item-level logicisCollapsedstate to manage manual expand/collapseisCollapsedwhen clicking on a selected itemuseEffectto resetisCollapsedwhen the item becomes deselectedSidebarItemfor cleaner structureKey Logic
Behavior
Before
After
Benefits
Testing
✅
npm run tsc(TypeScript compilation)✅
npm run lint(ESLint validation)All existing warnings were unrelated to this change
Sidebar Dropdown Should Toggle When Clicking an Already-Selected Item #8149