Skip to content

Commit f4d4fd0

Browse files
committed
🐛 Fix ref not forwarding to new buttons
1 parent 58b6f1c commit f4d4fd0

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

packages/ui/src/components/Button.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mergeProps, useRender } from "@base-ui-components/react";
2-
import type * as React from "react";
2+
import * as React from "react";
33
import { cn } from "../lib/cn";
44
import { cva, cx, type VariantProps } from "../lib/cva";
55

@@ -55,29 +55,26 @@ export interface ButtonProps
5555
extends useRender.ComponentProps<"button">,
5656
VariantProps<typeof buttonVariants> {}
5757

58-
const Button = ({
59-
className,
60-
variant,
61-
size,
62-
iconStyle,
63-
render,
64-
...props
65-
}: ButtonProps) => {
66-
const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] =
67-
render ? undefined : "button";
58+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
59+
({ className, variant, size, iconStyle, render, ...props }, ref) => {
60+
const typeValue: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] =
61+
render ? undefined : "button";
6862

69-
const defaultProps = {
70-
"data-slot": "button",
71-
"data-disabled": props.disabled,
72-
className: cn(buttonVariants({ variant, size, iconStyle, className })),
73-
type: typeValue,
74-
};
63+
const defaultProps = {
64+
"data-slot": "button",
65+
"data-disabled": props.disabled,
66+
className: cn(buttonVariants({ variant, size, iconStyle, className })),
67+
type: typeValue,
68+
};
7569

76-
return useRender({
77-
defaultTagName: "button",
78-
render,
79-
props: mergeProps<"button">(defaultProps, props),
80-
});
81-
};
70+
return useRender({
71+
ref,
72+
defaultTagName: "button",
73+
render,
74+
props: mergeProps<"button">(defaultProps, props),
75+
});
76+
},
77+
);
78+
Button.displayName = "Button";
8279

8380
export { Button, buttonVariants };

0 commit comments

Comments
 (0)