Skip to content

Commit 56c8d4c

Browse files
authored
Merge pull request #36 from oasisprotocol/ml/button-forward-ref
Fix Button forwardRef runtime error
2 parents 1914381 + 77a1e5e commit 56c8d4c

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/components/ui/button.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ const buttonVariants = cva(
3232
}
3333
)
3434

35-
function Button({
36-
className,
37-
variant,
38-
size,
39-
asChild = false,
40-
...props
41-
}: React.ComponentProps<'button'> &
42-
VariantProps<typeof buttonVariants> & {
43-
asChild?: boolean
44-
}) {
45-
const Comp = asChild ? Slot : 'button'
4635

47-
return <Comp data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} />
36+
export interface ButtonProps
37+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38+
VariantProps<typeof buttonVariants> {
39+
asChild?: boolean
4840
}
4941

42+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43+
({ className, variant, size, asChild = false, ...props }, ref) => {
44+
const Comp = asChild ? Slot : "button"
45+
return (
46+
<Comp
47+
className={cn(buttonVariants({ variant, size, className }))}
48+
ref={ref}
49+
{...props}
50+
/>
51+
)
52+
}
53+
)
54+
Button.displayName = "Button"
55+
5056
export { Button, buttonVariants }

0 commit comments

Comments
 (0)