You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package treats `ref` as an explicit component capability, not an accidental side effect of inheriting DOM props.
4
+
5
+
## Rules
6
+
7
+
- Use `React.ComponentPropsWithoutRef<'tag'>` for DOM-derived prop interfaces by default.
8
+
- Only expose `ref` when the component intentionally supports DOM access through `React.forwardRef`.
9
+
- Do not rely on `React.ComponentProps<'tag'>` to leak `ref` into props interfaces.
10
+
- If a component is primarily compositional or layout-only, do not expose `ref` unless there is a concrete DOM integration need.
11
+
12
+
## Components That Should Expose `ref`
13
+
14
+
- Interactive controls and focus targets such as `Button`, `Input`, `NativeSelect`, `Link`, `Switch`, `Checkbox`, `Radio`.
15
+
- Components frequently used for measurement, scrolling, positioning, or animation integration such as `Tree`, `Slider`, `Grid`, `Space`, `Flex`, `Layout`, `Anchor`, `Waterfall`, `Transfer`, `Steps`, and typography primitives.
16
+
17
+
## Components That Usually Should Not Expose `ref`
18
+
19
+
- Grouping or compositional wrappers such as `Button.Group`, `Checkbox.Group`, `Radio.Group`, `Input.Group`, `Input.Addon`, `Form.Item`, `Descriptions`, `Descriptions.Item`.
20
+
21
+
## Practical Guidance
22
+
23
+
- If consumers need the outer wrapper and an inner native control, expose both intentionally, for example `Checkbox` plus `checkboxRef`, or `Radio` plus `radioRef`.
24
+
- If a component renders different DOM elements by state, make the forwarded ref type reflect that reality instead of pretending it always points to one tag.
25
+
- When adding a new forwarded ref, add a focused test that proves the ref resolves to the expected DOM node.
0 commit comments