Explorar o código

fix: solve asChild attribute issue in custom button (#31)

Sat Naing hai 1 ano
pai
achega
bc75eab316
Modificáronse 1 ficheiros con 4 adicións e 4 borrados
  1. 4 4
      src/components/custom/button.tsx

+ 4 - 4
src/components/custom/button.tsx

@@ -1,9 +1,8 @@
 import * as React from 'react'
 import { Slot } from '@radix-ui/react-slot'
+import { IconLoader2 } from '@tabler/icons-react'
 import { cva, type VariantProps } from 'class-variance-authority'
-
 import { cn } from '@/lib/utils'
-import { IconLoader2 } from '@tabler/icons-react'
 
 const buttonVariants = cva(
   'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
@@ -52,12 +51,13 @@ type ButtonProps = ButtonPropsBase &
 
 const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
   ({ className, variant, size, children, ...props }, ref) => {
-    if (props.asChild) {
+    const { asChild, ...rest } = props
+    if (asChild) {
       return (
         <Slot
           className={cn(buttonVariants({ variant, size, className }))}
           ref={ref}
-          {...props}
+          {...rest}
         >
           {children}
         </Slot>