@@ -10,7 +10,7 @@ import {
1010 forwardRef ,
1111 useContext
1212} from 'react' ;
13- import { Avatar , getAvatarColor } from '../avatar' ;
13+ import { Avatar } from '../avatar' ;
1414import { Flex } from '../flex' ;
1515import { Tooltip } from '../tooltip' ;
1616import styles from './sidebar.module.css' ;
@@ -178,7 +178,13 @@ const SidebarItem = forwardRef<HTMLAnchorElement, SidebarItemProps>(
178178 ref
179179 ) => {
180180 const { isCollapsed, hideCollapsedItemTooltip } =
181- useContext ( SidebarContext ) ; // To prevent prop drillng
181+ useContext ( SidebarContext ) ;
182+
183+ const shouldShowFallback =
184+ leadingIcon == undefined &&
185+ isCollapsed &&
186+ typeof children === 'string' &&
187+ children . length > 0 ;
182188
183189 const content = cloneElement (
184190 as ,
@@ -199,16 +205,17 @@ const SidebarItem = forwardRef<HTMLAnchorElement, SidebarItemProps>(
199205 className = { cx ( styles [ 'nav-leading-icon' ] , classNames ?. leadingIcon ) }
200206 aria-hidden = 'true'
201207 >
202- { leadingIcon ||
203- ( typeof children === 'string' && children . length > 0 ? (
204- < Avatar
205- size = { 1 }
206- variant = 'soft'
207- color = { getAvatarColor ( children ) }
208- fallback = { children [ 0 ] . toUpperCase ( ) }
209- style = { { cursor : 'pointer' } }
210- />
211- ) : null ) }
208+ { shouldShowFallback ? (
209+ < Avatar
210+ size = { 1 }
211+ variant = 'soft'
212+ color = 'neutral'
213+ fallback = { children [ 0 ] . toUpperCase ( ) }
214+ style = { { cursor : 'pointer' } }
215+ />
216+ ) : (
217+ leadingIcon
218+ ) }
212219 </ Flex >
213220 { ! isCollapsed && < span className = { styles [ 'nav-text' ] } > { children } </ span > }
214221 </ >
0 commit comments