Skip to content

Commit d4fcf7f

Browse files
committed
refactor(react): normalize forwardRef props to ComponentPropsWithoutRef
The codebase mixed `ComponentProps` (with ref) and `ComponentPropsWithoutRef` across prop interfaces, all consumed by `React.forwardRef`. Normalize to `ComponentPropsWithoutRef` throughout — the idiomatic pattern React docs recommend for forwardRef, since forwardRef re-adds ref via `RefAttributes<T>` to the external component type. Side benefit: for the handful of non-forwardRef components (Link, Form, FormItem, Descriptions), this removes `ref` from the prop type so consumers can no longer pass a non-functional `ref` prop. Zero external API change for forwardRef components — `<Button ref={...}/>` still type-checks via `RefAttributes<HTMLButtonElement>`.
1 parent 666b141 commit d4fcf7f

26 files changed

Lines changed: 38 additions & 38 deletions

File tree

packages/react/src/anchor/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface AnchorProps extends BaseProps {
1212
children?: React.ReactNode;
1313
}
1414

15-
export interface AnchorLinkProps extends BaseProps, React.ComponentProps<'a'> {
15+
export interface AnchorLinkProps extends BaseProps, React.ComponentPropsWithoutRef<'a'> {
1616
href: string;
1717
title: string;
1818
children?: React.ReactElement<AnchorLinkProps>[];

packages/react/src/button/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type ButtonIconPosition = 'start' | 'end';
1212
export type ButtonGroupInheritMode = 'fill' | 'override' | 'none';
1313

1414
export interface ButtonProps
15-
extends BaseProps, React.ComponentProps<'button'> {
15+
extends BaseProps, React.ComponentPropsWithoutRef<'button'> {
1616
variant?: ButtonVariant;
1717
color?: ButtonColor;
1818
loading?: boolean;
@@ -27,7 +27,7 @@ export interface ButtonProps
2727
}
2828

2929
export interface ButtonGroupProps
30-
extends BaseProps, React.ComponentProps<'div'> {
30+
extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
3131
variant?: ButtonVariant;
3232
color?: ButtonColor;
3333
size?: SizeType;

packages/react/src/checkbox/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseProps } from '../_utils/props';
33

44
export interface CheckboxGroupProps
55
extends BaseProps,
6-
Omit<React.ComponentProps<'div'>, 'onChange'> {
6+
Omit<React.ComponentPropsWithoutRef<'div'>, 'onChange'> {
77
defaultValue?: string[];
88
value?: string[];
99
onChange?: (checkedValues: string[]) => void;
@@ -13,7 +13,7 @@ export interface CheckboxGroupProps
1313

1414
export interface CheckboxProps
1515
extends BaseProps,
16-
Omit<React.ComponentProps<'label'>, 'onChange'> {
16+
Omit<React.ComponentPropsWithoutRef<'label'>, 'onChange'> {
1717
/** Only required when use checkbox group */
1818
value?: string;
1919
defaultChecked?: boolean;

packages/react/src/descriptions/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface DescriptionsItemType extends BaseProps {
1717

1818
export interface DescriptionsProps
1919
extends BaseProps,
20-
Omit<React.ComponentProps<'div'>, 'title'> {
20+
Omit<React.ComponentPropsWithoutRef<'div'>, 'title'> {
2121
title?: React.ReactNode;
2222
extra?: React.ReactNode;
2323
footer?: React.ReactNode;

packages/react/src/flex/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { BaseProps, SizeType } from '../_utils/props';
33

4-
export interface FlexProps extends BaseProps, React.ComponentProps<'div'> {
4+
export interface FlexProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
55
vertical?: boolean;
66
wrap?: React.CSSProperties['flexWrap'];
77
justify?: React.CSSProperties['justifyContent'];

packages/react/src/form/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface FormOptionsProps {
6666
export interface FormProps
6767
extends BaseProps,
6868
Partial<FormOptionsProps>,
69-
React.ComponentProps<'form'> {
69+
React.ComponentPropsWithoutRef<'form'> {
7070
form?: FormInstance;
7171
initialValues?: FormValues;
7272
onFinish?: (values: FormValues) => void;

packages/react/src/grid/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type RowJustify =
1111
| 'space-between'
1212
| 'space-evenly';
1313

14-
export interface RowProps extends BaseProps, React.ComponentProps<'div'> {
14+
export interface RowProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
1515
gutter?: number | [number, number];
1616
gutterSide?: boolean;
1717
align?: RowAlign;
@@ -29,7 +29,7 @@ export type GridTrackValue = number | React.CSSProperties['gridTemplateColumns']
2929
export type GridItemSize = number | 'auto' | 'grow' | 'full';
3030
export type GridItemOffset = number | 'auto';
3131

32-
export interface GridProps extends BaseProps, React.ComponentProps<'div'> {
32+
export interface GridProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
3333
columns?: ResponsiveValue<GridTrackValue>;
3434
rows?: ResponsiveValue<React.CSSProperties['gridTemplateRows']>;
3535
spacing?: ResponsiveValue<SizeType | React.CSSProperties['gap']>;
@@ -51,7 +51,7 @@ export interface GridProps extends BaseProps, React.ComponentProps<'div'> {
5151
component?: React.ElementType;
5252
}
5353

54-
export interface GridItemProps extends BaseProps, React.ComponentProps<'div'> {
54+
export interface GridItemProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
5555
size?: ResponsiveValue<GridItemSize>;
5656
offset?: ResponsiveValue<GridItemOffset>;
5757
column?: ResponsiveValue<React.CSSProperties['gridColumn']>;
@@ -64,7 +64,7 @@ export interface GridItemProps extends BaseProps, React.ComponentProps<'div'> {
6464
component?: React.ElementType;
6565
}
6666

67-
export interface ColProps extends BaseProps, React.ComponentProps<'div'> {
67+
export interface ColProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
6868
span?: number;
6969
offset?: number;
7070
order?: number;

packages/react/src/input/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseProps, SizeType } from '../_utils/props';
33

44
export interface InputProps
55
extends BaseProps,
6-
Omit<React.ComponentProps<'input'>, 'size' | 'prefix'> {
6+
Omit<React.ComponentPropsWithoutRef<'input'>, 'size' | 'prefix'> {
77
clearable?: boolean;
88
prefix?: ReactNode;
99
suffix?: ReactNode;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { BaseProps } from '../_utils/props';
33

4-
export interface KeyboardProps extends BaseProps, React.ComponentProps<'kbd'> {
4+
export interface KeyboardProps extends BaseProps, React.ComponentPropsWithoutRef<'kbd'> {
55
children?: React.ReactNode;
66
}

packages/react/src/layout/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { BaseProps } from '../_utils/props';
33

4-
export interface LayoutProps extends BaseProps, React.ComponentProps<'div'> {}
4+
export interface LayoutProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {}
55

66
export type SidebarTheme = 'light' | 'dark';
77

8-
export interface SidebarProps extends BaseProps, React.ComponentProps<'div'> {
8+
export interface SidebarProps extends BaseProps, React.ComponentPropsWithoutRef<'div'> {
99
collapsible?: boolean;
1010
collapsed?: boolean;
1111
defaultCollapsed?: boolean;

0 commit comments

Comments
 (0)