feat: add tooltip support to SidebarMenuSubButton and update NavMain and NavSecondary components for improved accessibility

This commit is contained in:
mlogclub
2026-05-30 20:50:14 +08:00
parent 7e6fcc45ac
commit 57995e352b
4 changed files with 39 additions and 21 deletions
+22 -2
View File
@@ -668,14 +668,17 @@ function SidebarMenuSubButton({
render,
size = "md",
isActive = false,
tooltip,
className,
...props
}: useRender.ComponentProps<"a"> &
React.ComponentProps<"a"> & {
size?: "sm" | "md"
isActive?: boolean
tooltip?: string | React.ComponentProps<typeof TooltipContent>
}) {
return useRender({
const { isMobile } = useSidebar()
const comp = useRender({
defaultTagName: "a",
props: mergeProps<"a">(
{
@@ -686,7 +689,7 @@ function SidebarMenuSubButton({
},
props
),
render,
render: !tooltip ? render : <TooltipTrigger render={render} />,
state: {
slot: "sidebar-menu-sub-button",
sidebar: "menu-sub-button",
@@ -694,6 +697,23 @@ function SidebarMenuSubButton({
active: isActive,
},
})
if (!tooltip) {
return comp
}
if (typeof tooltip === "string") {
tooltip = {
children: tooltip,
}
}
return (
<Tooltip>
{comp}
<TooltipContent side="right" align="center" hidden={isMobile} {...tooltip} />
</Tooltip>
)
}
export {