Skip to content

Conversation

@GoldGroove06
Copy link
Contributor

@GoldGroove06 GoldGroove06 commented Jul 18, 2025

Screen.Recording.2025-07-18.133931.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a visual indicator for selected radio buttons.
    • Added new customization options for radio button appearance and structure.
  • Refactor

    • Updated radio button components to use a button-based approach for improved accessibility and flexibility.
    • Enhanced markup structure to better associate labels with radio buttons.
    • Reorganized component structure to wrap the entire radio group consistently and include a hidden input for form integration.
  • Bug Fixes

    • Improved accessibility by updating ARIA attributes and ensuring proper label associations.
  • Tests

    • Updated tests to reflect new component structure and accessibility improvements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

This change refactors the RadioGroupPrimitive component suite by replacing native radio inputs with a button-based approach, introducing a context-driven indicator, updating accessibility attributes, and restructuring the component hierarchy. It also updates related stories and tests to align with the new structure and usage patterns.

Changes

Files/Groups Change Summary
src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx Wraps each RadioGroupPrimitive.Item in a <label>, adds explicit styling, and incorporates the new Indicator component for visual selection feedback.
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx Adds static property Indicator to RadioGroupPrimitive, referencing the new Indicator component.
src/core/primitives/RadioGroup/context/RadioGroupPrimitiveItemContext.tsx Introduces a new context for item selection state, exports its interface and context.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveIndicator.tsx Adds a new conditional Indicator component that renders only when its item is selected.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx Refactors Item to use a button element, updates props, accessibility attributes, and provides selection state via context.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx Rearranges structure to wrap the group in a Primitive.div and adds a hidden radio input for form compatibility.
src/core/primitives/RadioGroup/tests/RadioGroupPrimtive.test.tsx Updates tests to use the new component structure, querying, and accessibility attributes.
src/core/primitives/RadioGroup/context/RadioGroupContext.tsx Removes name property from RadioGroupContextValue interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Label
    participant RadioGroupPrimitive.Item
    participant RadioGroupPrimitive.Context
    participant RadioGroupPrimitive.Indicator

    User->>Label: Clicks label text
    Label->>RadioGroupPrimitive.Item: Activates button
    RadioGroupPrimitive.Item->>RadioGroupPrimitive.Context: Updates selection state
    RadioGroupPrimitive.Context-->>RadioGroupPrimitive.Indicator: Provides itemSelected state
    RadioGroupPrimitive.Indicator-->>User: Renders indicator if selected
Loading

Suggested labels

automerge

Suggested reviewers

  • kotAPI

Poem

In the garden of code, where radios bloom bright,
Buttons now flutter, replacing old light.
Indicators twinkle when choices are made,
Contexts whisper secrets, selections displayed.
With labels and stories, the tests hop along—
The UI grows stronger, the code sings a song.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-18T08_46_20_584Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be3de10 and bc0cf87.

📒 Files selected for processing (4)
  • src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx (2 hunks)
  • src/core/primitives/RadioGroup/context/RadioGroupContext.tsx (0 hunks)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx (1 hunks)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • src/core/primitives/RadioGroup/context/RadioGroupContext.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx
  • src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx
⏰ 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
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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: 5

♻️ Duplicate comments (1)
src/core/primitives/RadioGroup/tests/RadioGroupPrimtive.test.tsx (1)

37-37: Replace non-null assertion with proper null checking

Same issue as above - avoid using non-null assertion operator.

🧹 Nitpick comments (1)
src/core/primitives/RadioGroup/tests/RadioGroupPrimtive.test.tsx (1)

22-22: Replace non-null assertion with proper null checking

Using the non-null assertion operator (!) can hide potential runtime errors if the element is not found. Consider adding proper null checks or using userEvent for better error messages.

-        fireEvent.click(radioA!);
+        if (radioA) fireEvent.click(radioA);

Alternatively, use @testing-library/user-event for better error handling:

import userEvent from '@testing-library/user-event';
// ...
await userEvent.click(radioA);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b43163 and be3de10.

📒 Files selected for processing (7)
  • src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx (2 hunks)
  • src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (2 hunks)
  • src/core/primitives/RadioGroup/context/RadioGroupPrimitiveItemContext.tsx (1 hunks)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveIndicator.tsx (1 hunks)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx (1 hunks)
  • src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx (1 hunks)
  • src/core/primitives/RadioGroup/tests/RadioGroupPrimtive.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: decipher-cs
PR: rad-ui/ui#417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the `Dropdown.Trigger` component in `src/components/ui/Dropdown/Dropdown.stories.tsx`.
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (1)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx (3)
Learnt from: decipher-cs
PR: rad-ui/ui#417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the `Dropdown.Trigger` component in `src/components/ui/Dropdown/Dropdown.stories.tsx`.
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
Learnt from: kotAPI
PR: rad-ui/ui#1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like `value`, `defaultValue`, and `onValueChange`. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx (1)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
src/core/primitives/RadioGroup/tests/RadioGroupPrimtive.test.tsx (2)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
Learnt from: decipher-cs
PR: rad-ui/ui#417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the `Dropdown.Trigger` component in `src/components/ui/Dropdown/Dropdown.stories.tsx`.
src/core/primitives/RadioGroup/context/RadioGroupPrimitiveItemContext.tsx (1)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx (3)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
Learnt from: decipher-cs
PR: rad-ui/ui#417
File: src/components/ui/Dropdown/Dropdown.stories.tsx:43-50
Timestamp: 2024-12-12T08:34:33.079Z
Learning: Ensure to verify existing ARIA attributes in components before suggesting additions during code reviews, especially in the `Dropdown.Trigger` component in `src/components/ui/Dropdown/Dropdown.stories.tsx`.
Learnt from: kotAPI
PR: rad-ui/ui#1031
File: src/components/ui/Accordion/fragments/AccordionRoot.tsx:41-44
Timestamp: 2025-04-07T04:38:34.864Z
Learning: The Accordion component in rad-ui/ui supports both controlled and uncontrolled modes through props like `value`, `defaultValue`, and `onValueChange`. When implementing controlled components, remember to: 1) Initialize state from defaultValue, 2) Update internal state when value changes (controlled mode), 3) Call onValueChange callback, and 4) Prevent internal state updates when in controlled mode.
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveIndicator.tsx (1)
Learnt from: kotAPI
PR: rad-ui/ui#576
File: src/core/primitives/Toggle/index.tsx:15-22
Timestamp: 2024-11-24T06:43:42.194Z
Learning: In the `TogglePrimitive` component (`src/core/primitives/Toggle/index.tsx`), when the component becomes controlled, it's acceptable to not sync the internal `isPressed` state with the external `pressed` prop.
🧬 Code Graph Analysis (1)
src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx (1)
src/components/ui/RadioGroup/context/RadioGroupContext.tsx (1)
  • RadioGroupContext (3-7)
🪛 Biome (1.9.4)
src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx

[error] 35-35: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 84-84: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ 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 (6)
src/core/primitives/RadioGroup/RadioGroupPrimitive.tsx (2)

5-5: Clean import addition.

The import follows the established pattern for fragment components.


19-19: Consistent static property pattern.

The Indicator property follows the same pattern as Root and Item, maintaining consistency in the API design.

src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveRoot.tsx (1)

36-48: Excellent structural refactoring for button-based approach.

The changes properly maintain accessibility and form compatibility:

  • The Primitive.div wrapper with role="radiogroup" provides proper semantic structure
  • The hidden input element ensures form submission works correctly
  • Accessibility attributes are correctly placed on the radiogroup container
  • The hidden input properly reflects the current state (selectedValue, groupDisabled, required)

This approach allows for custom button-based radio items while maintaining standard form behavior.

src/core/primitives/RadioGroup/RadioGroupPrimitive.stories.tsx (1)

36-39: Good demonstration of new component structure.

The story correctly shows the new pattern with:

  • Label wrapping the RadioGroupPrimitive.Item
  • Explicit styling classes on the item
  • Indicator component nested inside for visual feedback

This provides clear usage examples for the refactored API.

src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveIndicator.tsx (1)

10-15: Well-implemented conditional indicator component.

The implementation is clean and follows established patterns:

  • Proper use of context for state management
  • Efficient early return when not selected
  • Consistent API with other primitive components (asChild, className, children)
  • Uses Primitive.span for proper rendering flexibility
src/core/primitives/RadioGroup/context/RadioGroupPrimitiveItemContext.tsx (1)

9-11: Clean context implementation for item state.

The context is well-structured with:

  • Clear interface definition for the boolean state
  • Appropriate default value (false)
  • Proper TypeScript typing

This provides a clean way to share selection state between the item and indicator components.

aria-checked={value === selectedValue}
data-checked={value === selectedValue}
aria-required={required}
name={name}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unnecessary name attribute from button element

The name attribute on a button element doesn't serve any functional purpose for form submission. Based on the test file, it appears the name attribute should be on a hidden input element instead.

-                name={name}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name={name}
🤖 Prompt for AI Agents
In src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx at line
35, remove the name attribute from the button element because it is unnecessary
and does not affect form submission. Instead, ensure that the name attribute is
correctly applied to the hidden input element as indicated by the test file to
maintain proper form behavior.

<Primitive.button
disabled={groupDisabled || disabled}
onClick={() => setSelectedValue(value)}
onFocus={() => setSelectedValue(value)}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove onFocus handler to prevent unexpected selection changes

The onFocus handler changes the selected value when the button receives focus. This deviates from standard radio button behavior where selection should only change on user activation (click/space/enter), not on focus alone. This could cause accessibility issues and unexpected behavior during keyboard navigation.

-                onFocus={() => setSelectedValue(value)}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onFocus={() => setSelectedValue(value)}
🤖 Prompt for AI Agents
In src/core/primitives/RadioGroup/fragments/RadioGroupPrimitiveItem.tsx at line
30, remove the onFocus handler that sets the selected value on focus. This
handler causes the selection to change when the radio button gains focus, which
is not standard behavior. Ensure that selection only changes on explicit user
activation events like click, space, or enter, to maintain expected
accessibility and keyboard navigation behavior.

@kotAPI kotAPI added the automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met label Jul 19, 2025
@kodiakhq kodiakhq bot merged commit 0d2c37f into main Jul 19, 2025
6 checks passed
@kodiakhq kodiakhq bot deleted the new-radio-group-primitive branch July 19, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge A tag that tells kodiak bot to automerge PRs for us when tests and approval conditions are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants