Skip to content

Commit c7ea3f3

Browse files
committed
Update sidebar.tsx
1 parent 4464b49 commit c7ea3f3

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

packages/components/src/ui/sidebar.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ function Sidebar({
253253
)
254254
}
255255

256-
function SidebarTrigger({
257-
className,
258-
onClick,
259-
...props
260-
}: React.ComponentProps<typeof Button>) {
256+
const SidebarTrigger = React.forwardRef<
257+
HTMLButtonElement,
258+
React.ComponentProps<typeof Button>
259+
>(({ className, onClick, ...props }, ref) => {
261260
const { toggleSidebar } = useSidebar()
262261

263262
return (
264263
<Button
264+
ref={ref}
265265
data-sidebar="trigger"
266266
data-slot="sidebar-trigger"
267267
variant="ghost"
@@ -277,7 +277,8 @@ function SidebarTrigger({
277277
<span className="sr-only">Toggle Sidebar</span>
278278
</Button>
279279
)
280-
}
280+
})
281+
SidebarTrigger.displayName = "SidebarTrigger"
281282

282283
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
283284
const { toggleSidebar } = useSidebar()
@@ -495,24 +496,28 @@ const sidebarMenuButtonVariants = cva(
495496
}
496497
)
497498

498-
function SidebarMenuButton({
499+
const SidebarMenuButton = React.forwardRef<
500+
HTMLButtonElement,
501+
React.ComponentProps<"button"> & {
502+
asChild?: boolean
503+
isActive?: boolean
504+
tooltip?: string | React.ComponentProps<typeof TooltipContent>
505+
} & VariantProps<typeof sidebarMenuButtonVariants>
506+
>(({
499507
asChild = false,
500508
isActive = false,
501509
variant = "default",
502510
size = "default",
503511
tooltip,
504512
className,
505513
...props
506-
}: React.ComponentProps<"button"> & {
507-
asChild?: boolean
508-
isActive?: boolean
509-
tooltip?: string | React.ComponentProps<typeof TooltipContent>
510-
} & VariantProps<typeof sidebarMenuButtonVariants>) {
514+
}, ref) => {
511515
const Comp = asChild ? Slot : "button"
512516
const { isMobile, state } = useSidebar()
513517

514518
const button = (
515519
<Comp
520+
ref={ref}
516521
data-slot="sidebar-menu-button"
517522
data-sidebar="menu-button"
518523
data-size={size}
@@ -543,7 +548,8 @@ function SidebarMenuButton({
543548
/>
544549
</Tooltip>
545550
)
546-
}
551+
})
552+
SidebarMenuButton.displayName = "SidebarMenuButton"
547553

548554
function SidebarMenuAction({
549555
className,

0 commit comments

Comments
 (0)