# SidebarItem **📖 Live documentation:** https://cds.coinbase.com/components/navigation/SidebarItem/ A navigation item component designed to work within a Sidebar. ## Import ```tsx import { SidebarItem } from '@coinbase/cds-web/navigation/SidebarItem' ``` ## Examples ### Basics SidebarItem requires an `icon` and `title`. Place it inside a Sidebar component which provides context for collapsed state and variant styling. ```jsx live function BasicSidebarItem() { const [active, setActive] = useState(false); return ( }> setActive(!active)} title="Home" tooltipContent="Home" /> ); } ``` ### Active State Use the `active` prop to indicate the currently selected navigation item. The active state changes the text and icon color to provide visual feedback. ```jsx live function ActiveState() { const [activeIndex, setActiveIndex] = useState(0); const items = [ { title: 'Home', icon: 'home' }, { title: 'Assets', icon: 'chartPie' }, { title: 'Trade', icon: 'trading' }, { title: 'Settings', icon: 'cog' }, ]; return ( }> {items.map((item, index) => ( setActiveIndex(index)} title={item.title} tooltipContent={item.title} /> ))} ); } ``` ### Collapsed State When the parent Sidebar is collapsed, SidebarItem automatically hides the title text and shows only the icon. Use `tooltipContent` to display a tooltip on hover, which is essential for usability since the title is hidden. ```jsx live function CollapsedState() { const [collapsed, setCollapsed] = useState(true); const [activeIndex, setActiveIndex] = useState(0); const items = [ { title: 'Home', icon: 'home' }, { title: 'Assets', icon: 'chartPie' }, { title: 'Trade', icon: 'trading' }, ]; return ( } renderEnd={() => ( setCollapsed(!collapsed)} /> )} > {items.map((item, index) => ( setActiveIndex(index)} title={item.title} tooltipContent={item.title} /> ))} ); } ``` ### Styling #### Border Radius The default border radius is `1000` (pill shape) for the default sidebar variant. You can customize it with the `borderRadius` prop. ```jsx live function CustomBorderRadius() { return ( }> ); } ``` ### Custom Component Use the `Component` prop to render a completely custom layout while still benefiting from SidebarItem's state management. Your custom component receives `icon`, `title`, `color`, `active`, and `isCollapsed` props. ```jsx live function CustomComponent() { const [activeIndex, setActiveIndex] = useState(0); const items = [ { title: 'Dashboard', icon: 'home', badge: 3 }, { title: 'Messages', icon: 'speechBubble', badge: 12 }, { title: 'Analytics', icon: 'chartBar', badge: 0 }, ]; const CustomSidebarContent = ({ icon, title, color, active, isCollapsed }) => ( {!isCollapsed && ( {title} {items.find((i) => i.title === title)?.badge > 0 && ( {items.find((i) => i.title === title)?.badge} )} )} ); return ( }> {items.map((item, index) => ( setActiveIndex(index)} title={item.title} tooltipContent={item.title} /> ))} ); } ``` ### Accessibility SidebarItem automatically sets `accessibilityLabel` to the `title` value and uses `aria-current="page"` when active. When collapsed, the accessibility label is applied to the Pressable to ensure screen readers announce the item correctly. Provide a custom `accessibilityLabel` for more descriptive screen reader announcements. ```jsx live function Accessibility() { const [activeIndex, setActiveIndex] = useState(0); const items = [ { title: 'Home', icon: 'home', label: 'Navigate to home page' }, { title: 'Assets', icon: 'chartPie', label: 'View your asset portfolio' }, { title: 'Trade', icon: 'trading', label: 'Open trading interface' }, ]; return ( }> {items.map((item, index) => ( setActiveIndex(index)} title={item.title} tooltipContent={item.title} /> ))} ); } ``` ## Props | Prop | Type | Required | Default | Description | | --- | --- | --- | --- | --- | ## Styles | Selector | Static class name | Description | | --- | --- | --- | | `root` | `cds-SidebarItem` | Persistent outer wrapper across tooltip/non-tooltip variants. | | `content` | `cds-SidebarItem-content` | Default content wrapper element. | | `icon` | `cds-SidebarItem-icon` | Icon wrapper element. | | `title` | `cds-SidebarItem-title` | Title text element. |