Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 5, 2025

Summary

  • refactor RadioGroup and RadioGroupPrimitive to forward refs and expose static subcomponents with proper types
  • add comprehensive ref forwarding test covering label and ensure existing stories compile

Testing

  • npm test
  • npm run build:rollup

Summary by CodeRabbit

  • New Features

    • RadioGroup.Label now supports ref forwarding to the underlying label element.
  • Refactor

    • Consolidated RadioGroup into a single export with nested subcomponents (Root, Item, Indicator, Label) accessible via static properties.
    • Updated components to a ref-forwarding API for improved interoperability.
    • Adjusted props to align with generic div-based usage and set display names for clearer debugging.
  • Tests

    • Extended test coverage to include ref forwarding on RadioGroup.Label, alongside existing checks for Root, Item, and Indicator.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 5, 2025

Walkthrough

Refactors RadioGroup and RadioGroupPrimitive to forwardRef-based components with explicit div-based props and exported Element ref types. Consolidates public API to a single component exposing static subcomponents. Updates tests to assert ref forwarding, including for Label. Adds displayName assignments and public type aliases.

Changes

Cohort / File(s) Summary
UI RadioGroup component API refactor
src/components/ui/RadioGroup/RadioGroup.tsx
Converts to forwardRef with RadioGroupElement and RadioGroupProps based on React.ComponentPropsWithoutRef<'div'>. Attaches static subcomponents (Root, Item, Indicator, Label). Sets displayName. Maintains console warning placeholder render.
Tests: ref forwarding
src/components/ui/RadioGroup/tests/RadioGroup.test.tsx
Extends tests to verify ref forwarding for RadioGroup.Label to HTMLLabelElement. Updates test description to include label; retains existing checks for root, item, indicator.
Core primitive API refactor
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx
Refactors to forwardRef with RadioGroupPrimitiveElement and div-based RadioGroupProps. Adds namespace type aliases for Item and Indicator. Attaches static subcomponents, sets displayName, preserves console warning path.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant RG as RadioGroup (forwardRef)
  participant Root as RadioGroup.Root
  participant Item as RadioGroup.Item
  participant Ind as RadioGroup.Indicator
  participant Lab as RadioGroup.Label
  participant DOM as DOM Elements

  App->>RG: Render <RadioGroup ref={groupRef}>...</RadioGroup>
  RG-->>App: forwards ref (div)
  App->>Root: Render
  App->>Item: Render (n)
  App->>Ind: Render
  App->>Lab: Render with ref={labelRef}
  Lab-->>App: forwards ref (label)
  note over RG,Lab: New: explicit forwardRef typing and static subcomponents
  Root->>DOM: mount div
  Item->>DOM: mount item elements
  Ind->>DOM: mount indicator
  Lab->>DOM: mount label
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • GoldGroove06

Poem

A nibble of props, a hop of refs,
I groom my types with careful steps.
Root, Item, Indicator too—
Label now forwards, thank you!
In gardens of divs I proudly preen,
Static kits, forward and serene. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kotapi/refactor-radiogroup-to-use-forwardref

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/components/ui/RadioGroup/tests/RadioGroup.test.tsx (1)

102-123: Ref forwarding test reads well; consider minor ergonomics tweaks

Looks good and validates the intended HTML element types. Optional:

  • Prefer user-event over fireEvent for realistic interactions elsewhere in the suite.
  • For extra robustness across environments, you can add a fallback assertion like expect(labelRef.current?.tagName).toBe('LABEL') in addition to instanceof checks.
src/components/ui/RadioGroup/RadioGroup.tsx (2)

9-11: Redundant children in props

children is already included via React.ComponentPropsWithoutRef<'div'>. You can simplify.

-export type RadioGroupProps = React.ComponentPropsWithoutRef<'div'> & {
-    children?: React.ReactNode;
-};
+export type RadioGroupProps = React.ComponentPropsWithoutRef<'div'>;

20-23: Gate console.warn to dev-only

Avoid noisy logs in production while keeping DX in dev.

-const RadioGroup = React.forwardRef<RadioGroupElement, RadioGroupProps>((_props, _ref) => {
-    console.warn('Direct usage of RadioGroup is not supported. Please use RadioGroup.Root and RadioGroup.Item instead.');
-    return null;
-}) as RadioGroupComponent;
+const RadioGroup = React.forwardRef<RadioGroupElement, RadioGroupProps>((_props, _ref) => {
+    if (process.env.NODE_ENV !== 'production') {
+        console.warn('Direct usage of RadioGroup is not supported. Please use RadioGroup.Root and RadioGroup.Item instead.');
+    }
+    return null;
+}) as RadioGroupComponent;
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (3)

7-12: Redundant children in props

Same note as UI layer; children is already present on div props.

-export type RadioGroupProps = React.ComponentPropsWithoutRef<'div'> & {
-    children?: React.ReactNode;
-};
+export type RadioGroupProps = React.ComponentPropsWithoutRef<'div'>;

19-23: Fix warning copy; mention the correct component and gate to dev

The message references “RadioGroup” instead of “RadioGroupPrimitive”, which can confuse users. Also, avoid logging in production.

-const RadioGroupPrimitive = React.forwardRef<RadioGroupPrimitiveElement, RadioGroupProps>((_props, _ref) => {
-    console.warn('Direct usage of RadioGroup is not supported. Please use RadioGroup.Root, RadioGroup.Item, etc. instead.');
-    return null;
-}) as RadioGroupPrimitiveComponent;
+const RadioGroupPrimitive = React.forwardRef<RadioGroupPrimitiveElement, RadioGroupProps>((_props, _ref) => {
+    if (process.env.NODE_ENV !== 'production') {
+        console.warn(
+            'Direct usage of RadioGroupPrimitive is not supported. Please use RadioGroupPrimitive.Root, RadioGroupPrimitive.Item, etc. instead.'
+        );
+    }
+    return null;
+}) as RadioGroupPrimitiveComponent;

13-17: Composite type with statics is fine; consider centralizing warn copy

Optional: export a shared WARN_MESSAGE constant to keep UI and primitive messages in sync.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 361ecec and fae78f2.

📒 Files selected for processing (3)
  • src/components/ui/RadioGroup/RadioGroup.tsx (1 hunks)
  • src/components/ui/RadioGroup/tests/RadioGroup.test.tsx (2 hunks)
  • src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/ui/RadioGroup/RadioGroup.tsx (1)
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (1)
  • RadioGroupProps (9-11)
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (1)
src/components/ui/RadioGroup/RadioGroup.tsx (1)
  • RadioGroupProps (9-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
src/components/ui/RadioGroup/tests/RadioGroup.test.tsx (1)

39-39: No-op change; nothing to review here.

src/components/ui/RadioGroup/RadioGroup.tsx (2)

7-18: Type surface for element and composite component looks solid

Exported RadioGroupElement and the composite type with static fragments are correct and IDE-friendly.


27-30: Static fragment exposure is clear

Assignments for Root/Item/Indicator/Label are straightforward and match the public API.

src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (2)

26-30: Nice DX: namespaced prop types for subcomponents

The RadioGroupPrimitiveProps namespace is a helpful discoverability touch.


7-12: No conflicting barrel exports for RadioGroupProps
I didn’t find any index file re-exporting both UI and Primitive RadioGroupProps, so there’s no import-name collision risk.

@kotAPI kotAPI linked an issue Sep 5, 2025 that may be closed by this pull request
@kotAPI kotAPI merged commit 352afed into main Sep 5, 2025
8 checks passed
@kotAPI kotAPI deleted the kotapi/refactor-radiogroup-to-use-forwardref branch September 5, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RadioGroup [forwardRef refactor]

2 participants