From e27c4dcd92f2b3c90c2f7877c3a436a341d020a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B1=E3=82=A4=E3=83=A9?= Date: Tue, 10 Feb 2026 16:41:20 -0700 Subject: [PATCH] chore: replace usage of `forwardRef` with `ref` as a prop (#21956) --- site/src/components/Alert/Alert.tsx | 30 ++- site/src/components/Avatar/Avatar.tsx | 21 +- site/src/components/Badge/Badge.tsx | 45 ++--- site/src/components/Badges/Badges.tsx | 34 ++-- site/src/components/Breadcrumb/Breadcrumb.tsx | 180 +++++++++--------- site/src/components/Button/Button.tsx | 58 +++--- site/src/components/Checkbox/Checkbox.tsx | 51 +++-- .../ExternalImage/ExternalImage.tsx | 11 +- site/src/components/Form/Form.tsx | 78 ++++---- site/src/components/Input/Input.tsx | 13 +- site/src/components/InputGroup/InputGroup.tsx | 19 +- site/src/components/Label/Label.tsx | 23 ++- site/src/components/Link/Link.tsx | 47 +++-- site/src/components/Pill/Pill.tsx | 62 +++--- site/src/components/Popover/Popover.tsx | 55 +++--- site/src/components/RadioGroup/RadioGroup.tsx | 30 ++- site/src/components/ScrollArea/ScrollArea.tsx | 74 ++++--- site/src/components/Select/Select.tsx | 115 +++++------ site/src/components/SelectMenu/SelectMenu.tsx | 14 +- site/src/components/Slider/Slider.tsx | 49 +++-- site/src/components/Stack/Stack.tsx | 13 +- .../StatusIndicator/StatusIndicator.tsx | 35 ++-- site/src/components/Switch/Switch.tsx | 11 +- site/src/components/Textarea/Textarea.tsx | 14 +- .../src/components/Timeline/TimelineEntry.tsx | 15 +- site/src/components/Tooltip/Tooltip.tsx | 18 +- .../NotificationsInbox/InboxButton.tsx | 50 +++-- site/src/modules/resources/AgentButton.tsx | 10 +- .../LicensesSettingsPage/LicenseCard.tsx | 14 +- site/src/pages/HealthPage/Content.tsx | 9 +- .../TemplateScheduleAutostart.tsx | 2 +- 31 files changed, 546 insertions(+), 654 deletions(-) diff --git a/site/src/components/Alert/Alert.tsx b/site/src/components/Alert/Alert.tsx index 6db0a99ff2..9bb73908c2 100644 --- a/site/src/components/Alert/Alert.tsx +++ b/site/src/components/Alert/Alert.tsx @@ -7,13 +7,7 @@ import { TriangleAlertIcon, XIcon, } from "lucide-react"; -import { - type FC, - forwardRef, - type PropsWithChildren, - type ReactNode, - useState, -} from "react"; +import { type FC, type ReactNode, useState } from "react"; import { cn } from "utils/cn"; const alertVariants = cva( @@ -131,7 +125,9 @@ export const Alert: FC = ({ ); }; -export const AlertDetail: FC = ({ children }) => { +export const AlertDetail: React.FC = ({ + children, +}) => { return ( {children} @@ -139,13 +135,11 @@ export const AlertDetail: FC = ({ children }) => { ); }; -export const AlertTitle = forwardRef< - HTMLHeadingElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( -

-)); +export const AlertTitle: React.FC> = ({ + className, + ...props +}) => { + return ( +

+ ); +}; diff --git a/site/src/components/Avatar/Avatar.tsx b/site/src/components/Avatar/Avatar.tsx index 3b9de3657d..e2e8637d67 100644 --- a/site/src/components/Avatar/Avatar.tsx +++ b/site/src/components/Avatar/Avatar.tsx @@ -13,7 +13,6 @@ import { useTheme } from "@emotion/react"; import * as AvatarPrimitive from "@radix-ui/react-avatar"; import { cva, type VariantProps } from "class-variance-authority"; -import * as React from "react"; import { getExternalImageStylesFromUrl } from "theme/externalImages"; import { cn } from "utils/cn"; @@ -58,17 +57,22 @@ export type AvatarProps = AvatarPrimitive.AvatarProps & VariantProps & { src?: string; fallback?: string; + ref?: React.Ref>; }; -const Avatar = React.forwardRef< - React.ElementRef, - AvatarProps ->(({ className, size, variant, src, fallback, children, ...props }, ref) => { +export const Avatar: React.FC = ({ + className, + size, + variant, + src, + fallback, + children, + ...props +}) => { const theme = useTheme(); return ( @@ -85,7 +89,4 @@ const Avatar = React.forwardRef< {children} ); -}); -Avatar.displayName = AvatarPrimitive.Root.displayName; - -export { Avatar }; +}; diff --git a/site/src/components/Badge/Badge.tsx b/site/src/components/Badge/Badge.tsx index df542e4678..9c12fca7d7 100644 --- a/site/src/components/Badge/Badge.tsx +++ b/site/src/components/Badge/Badge.tsx @@ -4,7 +4,6 @@ */ import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; -import { forwardRef } from "react"; import { cn } from "utils/cn"; const badgeVariants = cva( @@ -58,28 +57,26 @@ const badgeVariants = cva( }, ); -interface BadgeProps - extends React.HTMLAttributes, - VariantProps { - asChild?: boolean; -} +type BadgeProps = React.ComponentPropsWithRef<"div"> & + VariantProps & { + asChild?: boolean; + }; -export const Badge = forwardRef( - ( - { className, variant, size, border, hover, asChild = false, ...props }, - ref, - ) => { - const Comp = asChild ? Slot : "div"; +export const Badge: React.FC = ({ + className, + variant, + size, + border, + hover, + asChild = false, + ...props +}) => { + const Comp = asChild ? Slot : "div"; - return ( - - ); - }, -); + return ( + + ); +}; diff --git a/site/src/components/Badges/Badges.tsx b/site/src/components/Badges/Badges.tsx index 9cd62de362..4de9539053 100644 --- a/site/src/components/Badges/Badges.tsx +++ b/site/src/components/Badges/Badges.tsx @@ -1,13 +1,7 @@ import { Badge } from "components/Badge/Badge"; import { Stack } from "components/Stack/Stack"; -import { - type FC, - forwardRef, - type HTMLAttributes, - type PropsWithChildren, -} from "react"; -export const EnabledBadge: FC = () => { +export const EnabledBadge: React.FC = () => { return ( Enabled @@ -15,25 +9,25 @@ export const EnabledBadge: FC = () => { ); }; -export const EntitledBadge: FC = () => { +export const EntitledBadge: React.FC = () => { return ( Entitled ); }; -export const DisabledBadge: FC = forwardRef< - HTMLDivElement, - HTMLAttributes ->((props, ref) => { + +export const DisabledBadge: React.FC> = ({ + ...props +}) => { return ( - + Disabled ); -}); +}; -export const EnterpriseBadge: FC = () => { +export const EnterpriseBadge: React.FC = () => { return ( Enterprise @@ -45,7 +39,7 @@ interface PremiumBadgeProps { children?: React.ReactNode; } -export const PremiumBadge: FC = ({ +export const PremiumBadge: React.FC = ({ children = "Premium", }) => { return ( @@ -55,7 +49,7 @@ export const PremiumBadge: FC = ({ ); }; -export const PreviewBadge: FC = () => { +export const PreviewBadge: React.FC = () => { return ( Preview @@ -63,7 +57,7 @@ export const PreviewBadge: FC = () => { ); }; -export const AlphaBadge: FC = () => { +export const AlphaBadge: React.FC = () => { return ( Alpha @@ -71,7 +65,7 @@ export const AlphaBadge: FC = () => { ); }; -export const DeprecatedBadge: FC = () => { +export const DeprecatedBadge: React.FC = () => { return ( Deprecated @@ -79,7 +73,7 @@ export const DeprecatedBadge: FC = () => { ); }; -export const Badges: FC = ({ children }) => { +export const Badges: React.FC = ({ children }) => { return ( & { - separator?: ReactNode; - } ->(({ ...props }, ref) =>