Skip to content

Commit cb29eb4

Browse files
committed
refactor: update React.ElementRef to React.ComponentRef in UI components for better type safety
1 parent 7fc15ea commit cb29eb4

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

components/ui/accordion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { cn } from "@/lib/utils"
99
const Accordion = AccordionPrimitive.Root
1010

1111
const AccordionItem = React.forwardRef<
12-
React.ElementRef<typeof AccordionPrimitive.Item>,
12+
React.ComponentRef<typeof AccordionPrimitive.Item>,
1313
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
1414
>(({ className, ...props }, ref) => (
1515
<AccordionPrimitive.Item
@@ -21,7 +21,7 @@ const AccordionItem = React.forwardRef<
2121
AccordionItem.displayName = "AccordionItem"
2222

2323
const AccordionTrigger = React.forwardRef<
24-
React.ElementRef<typeof AccordionPrimitive.Trigger>,
24+
React.ComponentRef<typeof AccordionPrimitive.Trigger>,
2525
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
2626
>(({ className, children, ...props }, ref) => (
2727
<AccordionPrimitive.Header className="flex">
@@ -41,7 +41,7 @@ const AccordionTrigger = React.forwardRef<
4141
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
4242

4343
const AccordionContent = React.forwardRef<
44-
React.ElementRef<typeof AccordionPrimitive.Content>,
44+
React.ComponentRef<typeof AccordionPrimitive.Content>,
4545
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
4646
>(({ className, children, ...props }, ref) => (
4747
<AccordionPrimitive.Content

components/ui/dialog.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const DialogPortal = DialogPrimitive.Portal
1414
const DialogClose = DialogPrimitive.Close
1515

1616
const DialogOverlay = React.forwardRef<
17-
React.ElementRef<typeof DialogPrimitive.Overlay>,
17+
React.ComponentRef<typeof DialogPrimitive.Overlay>,
1818
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
1919
>(({ className, ...props }, ref) => (
2020
<DialogPrimitive.Overlay
@@ -29,7 +29,7 @@ const DialogOverlay = React.forwardRef<
2929
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
3030

3131
const DialogContent = React.forwardRef<
32-
React.ElementRef<typeof DialogPrimitive.Content>,
32+
React.ComponentRef<typeof DialogPrimitive.Content>,
3333
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
3434
>(({ className, children, ...props }, ref) => (
3535
<DialogPortal>
@@ -201,7 +201,7 @@ const DialogFooter = ({
201201
DialogFooter.displayName = "DialogFooter"
202202

203203
const DialogTitle = React.forwardRef<
204-
React.ElementRef<typeof DialogPrimitive.Title>,
204+
React.ComponentRef<typeof DialogPrimitive.Title>,
205205
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
206206
>(({ className, ...props }, ref) => (
207207
<DialogPrimitive.Title
@@ -216,7 +216,7 @@ const DialogTitle = React.forwardRef<
216216
DialogTitle.displayName = DialogPrimitive.Title.displayName
217217

218218
const DialogDescription = React.forwardRef<
219-
React.ElementRef<typeof DialogPrimitive.Description>,
219+
React.ComponentRef<typeof DialogPrimitive.Description>,
220220
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
221221
>(({ className, ...props }, ref) => (
222222
<DialogPrimitive.Description

components/ui/hover-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const HoverCard = HoverCardPrimitive.Root
1010
const HoverCardTrigger = HoverCardPrimitive.Trigger
1111

1212
const HoverCardContent = React.forwardRef<
13-
React.ElementRef<typeof HoverCardPrimitive.Content>,
13+
React.ComponentRef<typeof HoverCardPrimitive.Content>,
1414
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
1515
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
1616
<HoverCardPrimitive.Content

components/ui/input-otp.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Dot } from "lucide-react"
77
import { cn } from "@/lib/utils"
88

99
const InputOTP = React.forwardRef<
10-
React.ElementRef<typeof OTPInput>,
10+
React.ComponentRef<typeof OTPInput>,
1111
React.ComponentPropsWithoutRef<typeof OTPInput>
1212
>(({ className, containerClassName, ...props }, ref) => (
1313
<OTPInput
@@ -23,15 +23,15 @@ const InputOTP = React.forwardRef<
2323
InputOTP.displayName = "InputOTP"
2424

2525
const InputOTPGroup = React.forwardRef<
26-
React.ElementRef<"div">,
26+
React.ComponentRef<"div">,
2727
React.ComponentPropsWithoutRef<"div">
2828
>(({ className, ...props }, ref) => (
2929
<div ref={ref} className={cn("flex items-center", className)} {...props} />
3030
))
3131
InputOTPGroup.displayName = "InputOTPGroup"
3232

3333
const InputOTPSlot = React.forwardRef<
34-
React.ElementRef<"div">,
34+
React.ComponentRef<"div">,
3535
React.ComponentPropsWithoutRef<"div"> & { index: number }
3636
>(({ index, className, ...props }, ref) => {
3737
const inputOTPContext = React.useContext(OTPInputContext)
@@ -59,7 +59,7 @@ const InputOTPSlot = React.forwardRef<
5959
InputOTPSlot.displayName = "InputOTPSlot"
6060

6161
const InputOTPSeparator = React.forwardRef<
62-
React.ElementRef<"div">,
62+
React.ComponentRef<"div">,
6363
React.ComponentPropsWithoutRef<"div">
6464
>(({ ...props }, ref) => (
6565
<div ref={ref} role="separator" {...props}>

components/ui/radio-group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Circle } from "lucide-react"
77
import { cn } from "@/lib/utils"
88

99
const RadioGroup = React.forwardRef<
10-
React.ElementRef<typeof RadioGroupPrimitive.Root>,
10+
React.ComponentRef<typeof RadioGroupPrimitive.Root>,
1111
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
1212
>(({ className, ...props }, ref) => {
1313
return (
@@ -21,7 +21,7 @@ const RadioGroup = React.forwardRef<
2121
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName
2222

2323
const RadioGroupItem = React.forwardRef<
24-
React.ElementRef<typeof RadioGroupPrimitive.Item>,
24+
React.ComponentRef<typeof RadioGroupPrimitive.Item>,
2525
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
2626
>(({ className, ...props }, ref) => {
2727
return (

components/ui/toggle-group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ToggleGroupContext = React.createContext<
1515
})
1616

1717
const ToggleGroup = React.forwardRef<
18-
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
18+
React.ComponentRef<typeof ToggleGroupPrimitive.Root>,
1919
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
2020
VariantProps<typeof toggleVariants>
2121
>(({ className, variant, size, children, ...props }, ref) => (
@@ -33,7 +33,7 @@ const ToggleGroup = React.forwardRef<
3333
ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName
3434

3535
const ToggleGroupItem = React.forwardRef<
36-
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
36+
React.ComponentRef<typeof ToggleGroupPrimitive.Item>,
3737
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
3838
VariantProps<typeof toggleVariants>
3939
>(({ className, children, variant, size, ...props }, ref) => {

components/ui/toggle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const toggleVariants = cva(
2929
)
3030

3131
const Toggle = React.forwardRef<
32-
React.ElementRef<typeof TogglePrimitive.Root>,
32+
React.ComponentRef<typeof TogglePrimitive.Root>,
3333
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
3434
VariantProps<typeof toggleVariants>
3535
>(({ className, variant, size, ...props }, ref) => (

0 commit comments

Comments
 (0)