Skip to content

Commit

Permalink
fix(component): use 1st letter of text in collapsed Sidebar.Item wi…
Browse files Browse the repository at this point in the history
…th no `icon`

resolve #81
  • Loading branch information
tulup-conner committed Aug 20, 2022
1 parent a9a9a87 commit 8f0d24c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lib/components/Sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ const SidebarItem: FC<SidebarItemProps> = ({
const { isInsideCollapse } = useSidebarItemContext();
const theme = useTheme().theme.sidebar.item;

const Wrapper: FC<PropsWithChildren<unknown>> = ({ children: Component }) => (
const ListItem: FC<PropsWithChildren> = ({ children: wrapperChildren }) => (
<li>
{isCollapsed ? (
<Tooltip content={<Children>{children}</Children>} placement="right">
{Component}
<Tooltip content={<TooltipContent>{children}</TooltipContent>} placement="right">
{wrapperChildren}
</Tooltip>
) : (
Component
wrapperChildren
)}
</li>
);

const Children: FC<PropsWithChildren<unknown>> = ({ children }) => (
const TooltipContent: FC<PropsWithChildren> = ({ children }) => <Children>{children}</Children>;

const Children: FC<PropsWithChildren> = ({ children }) => (
<span
className={classNames(theme.content.base)}
data-testid="flowbite-sidebar-item-content"
Expand All @@ -62,7 +64,7 @@ const SidebarItem: FC<SidebarItemProps> = ({
);

return (
<Wrapper>
<ListItem>
<Component
aria-labelledby={`flowbite-sidebar-item-${id}`}
className={classNames(
Expand All @@ -79,14 +81,17 @@ const SidebarItem: FC<SidebarItemProps> = ({
data-testid="flowbite-sidebar-item-icon"
/>
)}
{isCollapsed && !Icon && (
<span className={theme.collapsed.noIcon}>{(children as string).charAt(0).toLocaleUpperCase() ?? '?'}</span>
)}
{!isCollapsed && <Children>{children}</Children>}
{label && !isCollapsed && (
{!isCollapsed && label && (
<Badge color={labelColor} data-testid="flowbite-sidebar-label" hidden={isCollapsed}>
{label}
</Badge>
)}
</Component>
</Wrapper>
</ListItem>
);
};

Expand Down

0 comments on commit 8f0d24c

Please sign in to comment.