Skip to content

feat(v3): CheckboxGroup, FieldCheckboxGroup #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: v3-main
Choose a base branch
from

Conversation

ntatoud
Copy link
Member

@ntatoud ntatoud commented Jul 5, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a Checkbox Group UI component with customizable options and support for nested groups.
    • Added a form-integrated FieldCheckboxGroup component with validation and accessibility enhancements.
    • Enhanced Checkbox component to support a "parent" state for hierarchical selection.
  • Documentation

    • Added Storybook stories demonstrating various CheckboxGroup and FieldCheckboxGroup usage scenarios.
  • Style

    • Improved visual feedback for invalid states in RadioGroup and Checkbox components, enhancing accessibility and user experience.
  • Refactor

    • Simplified and centralized invalid state handling in RadioGroup for more consistent accessibility.

@ntatoud ntatoud added enhancement New feature or request components Related to a Start UI custom component v3 labels Jul 5, 2025
Copy link
Contributor

coderabbitai bot commented Jul 5, 2025

Walkthrough

New CheckboxGroup and FieldCheckboxGroup components are introduced, along with Storybook stories demonstrating their usage, including nested and form-integrated scenarios. The form controller is updated to support the new checkbox group type. Accessibility and validation handling are improved for both checkbox and radio group components, with enhanced UI states and error styling.

Changes

File(s) Change Summary
app/components/form/field-checkbox-group/index.tsx Added new FieldCheckboxGroup component and its props type for react-hook-form integration.
app/components/form/field-checkbox-group/docs.stories.tsx Added Storybook stories for FieldCheckboxGroup with Zod validation and form integration.
app/components/form/form-field-controller.tsx Extended form field controller to support the new "checkbox-group" type and render FieldCheckboxGroup.
app/components/ui/checkbox-group.tsx Introduced CheckboxGroup component wrapping a base UI primitive with default styling and props forwarding.
app/components/ui/checkbox-group.stories.tsx Added Storybook stories for CheckboxGroup, including default, disabled, and nested group scenarios.
app/components/ui/checkbox.tsx Enhanced Checkbox with a new parent prop for parent/child UI states and conditional rendering logic.
app/components/form/field-radio-group/index.tsx Refactored error/invalid state handling for consistent accessibility attributes on radio group and options.
app/components/ui/radio-group.tsx Added conditional styling for invalid state on radio buttons using Tailwind classes.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Storybook
  participant FieldCheckboxGroup
  participant ReactHookForm
  participant Zod
  participant CheckboxGroup
  participant Checkbox

  User->>Storybook: Interacts with FieldCheckboxGroup story
  Storybook->>FieldCheckboxGroup: Renders form
  FieldCheckboxGroup->>ReactHookForm: Registers field with Zod validation
  ReactHookForm->>Zod: Validates input on blur/submit
  FieldCheckboxGroup->>CheckboxGroup: Passes value, onValueChange, accessibility props
  CheckboxGroup->>Checkbox: Renders options as checkboxes
  User->>Checkbox: Selects/deselects options
  Checkbox->>CheckboxGroup: Triggers onValueChange
  CheckboxGroup->>FieldCheckboxGroup: Updates form state
  FieldCheckboxGroup->>ReactHookForm: Updates controlled value
  ReactHookForm->>Zod: Re-validates if needed
Loading
sequenceDiagram
  participant User
  participant CheckboxGroup
  participant Checkbox (Parent)
  participant Checkbox (Child)

  User->>Checkbox (Parent): Toggles parent checkbox
  Checkbox (Parent)->>CheckboxGroup: Selects/deselects all children
  CheckboxGroup->>Checkbox (Child): Updates checked state

  User->>Checkbox (Child): Toggles child checkbox
  Checkbox (Child)->>CheckboxGroup: Updates value array
  CheckboxGroup->>Checkbox (Parent): Updates indeterminate/checked state
Loading

Suggested reviewers

  • yoannfleurydev
✨ 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

vercel bot commented Jul 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
start-ui ❌ Failed (Inspect) Jul 11, 2025 0:18am
start-ui-web-restart 🔄 Building (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 0:18am

Base automatically changed from v3/feat-field-checkbox to v3-main July 11, 2025 12:01
Copy link

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

🧹 Nitpick comments (3)
app/components/ui/checkbox.tsx (1)

44-87: Consider adding aria-invalid support to parent state for consistency.

The parent state implementation is comprehensive but lacks aria-invalid styling that's present in the default state. This might be needed for form validation consistency.

Consider adding aria-invalid styling to the parent state className:

className={cn(
  'flex size-5 cursor-pointer items-center justify-center rounded-sm outline-none',
  'focus-visible:ring-[3px] focus-visible:ring-ring/50',
+ 'aria-invalid:focus-visible:ring-destructive/50 aria-invalid:data-unchecked:border-destructive',
  'data-checked:bg-primary data-unchecked:border data-unchecked:border-primary/50',
  'disabled:cursor-not-allowed disabled:bg-muted-foreground disabled:opacity-20',
  className
)}
app/components/form/field-checkbox-group/index.tsx (1)

58-61: Consider removing empty className

The container div has an empty className string which serves no purpose.

-            className={cn('', containerProps?.className)}
+            className={cn(containerProps?.className)}
app/components/ui/checkbox-group.stories.tsx (1)

101-116: Review the parent-child synchronization logic

The logic for synchronizing parent and child checkbox states could be more robust. Currently, when "bear-3" is selected, it automatically selects all little bears, but the reverse logic might not work as expected in all scenarios.

Consider extracting this logic into a custom hook for better testability and reusability:

const useNestedCheckboxSync = (parentValue: string, childValues: string[]) => {
  // Implementation for parent-child synchronization
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2beb30b and 68f9828.

📒 Files selected for processing (8)
  • app/components/form/field-checkbox-group/docs.stories.tsx (1 hunks)
  • app/components/form/field-checkbox-group/index.tsx (1 hunks)
  • app/components/form/field-radio-group/index.tsx (4 hunks)
  • app/components/form/form-field-controller.tsx (3 hunks)
  • app/components/ui/checkbox-group.stories.tsx (1 hunks)
  • app/components/ui/checkbox-group.tsx (1 hunks)
  • app/components/ui/checkbox.tsx (3 hunks)
  • app/components/ui/radio-group.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
app/components/form/field-radio-group/index.tsx (1)
app/components/ui/radio-group.tsx (1)
  • Radio (26-67)
app/components/ui/checkbox-group.tsx (1)
app/lib/tailwind/utils.ts (1)
  • cn (4-6)
app/components/ui/checkbox.tsx (1)
app/lib/tailwind/utils.ts (1)
  • cn (4-6)
app/components/form/field-checkbox-group/index.tsx (5)
app/components/ui/checkbox.tsx (2)
  • CheckboxProps (8-14)
  • Checkbox (16-117)
app/components/form/form-field-controller.tsx (1)
  • FieldProps (40-47)
app/components/ui/checkbox-group.tsx (1)
  • CheckboxGroup (7-17)
app/components/form/form-field.tsx (1)
  • useFormField (50-56)
app/lib/tailwind/utils.ts (1)
  • cn (4-6)
app/components/ui/checkbox-group.stories.tsx (2)
app/components/ui/checkbox-group.tsx (1)
  • CheckboxGroup (7-17)
app/components/ui/checkbox.tsx (1)
  • Checkbox (16-117)
⏰ 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: Playwright E2E Tests
🔇 Additional comments (19)
app/components/form/form-field-controller.tsx (3)

13-16: Import statement follows established patterns.

The import is correctly placed and follows the same structure as other field component imports.


61-62: Union type extension is correctly implemented.

The FieldCheckboxGroupProps is properly added to the union type, maintaining consistency with the existing field types.


105-106: Switch case implementation follows established pattern.

The new case for 'checkbox-group' is correctly implemented and positioned appropriately before the generic comment marker.

app/components/form/field-radio-group/index.tsx (2)

56-56: Good refactoring to centralize invalid state logic.

Creating a local isInvalid constant eliminates repetition and improves maintainability. The boolean conversion is correct for the aria-invalid attribute.


67-67: Consistent application of invalid state across components.

The isInvalid constant is properly applied to the RadioGroup, renderOption, and Radio components, ensuring consistent accessibility semantics.

Also applies to: 86-86, 95-102

app/components/ui/radio-group.tsx (1)

48-48: Enhanced styling for invalid states improves user experience.

The added Tailwind classes provide appropriate visual feedback for invalid radio buttons, complementing the aria-invalid attribute usage in the form components.

app/components/ui/checkbox.tsx (2)

36-40: Good use of UI state management for different checkbox variants.

The getUiState usage effectively handles the different UI states based on the parent prop, providing a clean separation of concerns.


88-112: Default state maintains existing functionality with enhanced validation styling.

The default state implementation preserves the original checkbox behavior while adding appropriate aria-invalid styling for form validation.

app/components/form/field-checkbox-group/docs.stories.tsx (4)

1-18: LGTM: Clean imports and story setup

The imports are well-organized and the Storybook meta configuration is properly set up for the FieldCheckboxGroup component.


20-26: LGTM: Proper form validation schema

The Zod schema correctly validates for a non-empty array of strings with a clear error message. The use of zu.array.nonEmpty is appropriate for checkbox group validation.


28-34: LGTM: Appropriate form configuration

The form options are properly configured with onBlur mode for validation timing and correct default values for the checkbox group.


42-64: LGTM: Well-structured form story

The story demonstrates proper integration of the FieldCheckboxGroup within a form context, including proper form field structure with label, helper text, and submission handling.

app/components/form/field-checkbox-group/index.tsx (2)

62-85: LGTM: Excellent accessibility implementation

The CheckboxGroup implementation properly handles all accessibility concerns:

  • Correct ARIA attributes linking to form field context
  • Proper error state handling in aria-describedby
  • Individual checkbox accessibility attributes
  • Clean props spreading and value management

49-91: LGTM: Solid Controller integration

The react-hook-form Controller is properly integrated with all necessary props and correct render prop usage. The field state management and error handling are well implemented.

app/components/ui/checkbox-group.stories.tsx (5)

7-16: LGTM: Clean story setup

The Storybook meta configuration and test data structure are well-organized. The astrobears data includes all necessary properties for demonstrating different checkbox states.


18-28: LGTM: Simple default story

The default story properly demonstrates basic CheckboxGroup usage with mapped options.


30-68: LGTM: Good coverage of checkbox states

The DefaultValue, Disabled, and DisabledOption stories provide comprehensive coverage of different checkbox group states and behaviors.


137-145: LGTM: Solid child-to-parent synchronization

The logic for updating the parent when all children are selected/deselected is well-implemented. The use of Array.from(new Set([...prev, 'bear-3'])) ensures no duplicates are added.


103-168: LGTM: Comprehensive nested group demonstration

The WithNestedGroups story effectively demonstrates the parent checkbox functionality and complex state management for hierarchical checkbox groups. The visual indentation with pl-4 classes makes the hierarchy clear.

Comment on lines +11 to +14
className={cn(
'className="flex flex-col items-start gap-1',
props?.className
)}
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

Fix syntax error in className string.

There's a syntax error in the className string on line 12 where "className= is included in the string literal.

Apply this diff to fix the syntax error:

-      className={cn(
-        'className="flex flex-col items-start gap-1',
-        props?.className
-      )}
+      className={cn(
+        'flex flex-col items-start gap-1',
+        props?.className
+      )}
📝 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
className={cn(
'className="flex flex-col items-start gap-1',
props?.className
)}
className={cn(
'flex flex-col items-start gap-1',
props?.className
)}
🤖 Prompt for AI Agents
In app/components/ui/checkbox-group.tsx around lines 11 to 14, remove the
incorrect inclusion of 'className=' inside the string literal passed to the cn
function. The className string should only contain the CSS classes without the
'className=' prefix. Fix the syntax by deleting 'className=' from the string.

@@ -17,6 +18,7 @@ export function Checkbox({
className,
noLabel,
labelProps,
parent,
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

Missing parent prop in CheckboxProps type definition.

The parent prop is used in the component but not defined in the CheckboxProps type interface.

Add the parent prop to the CheckboxProps type:

export type CheckboxProps = Omit<CheckboxPrimitive.Root.Props, 'type'> & {
  /**
   * By default, the checkbox is wrapped in a `<label>`. Set to `false` if you do not want it.
   */
  noLabel?: boolean;
  labelProps?: React.ComponentProps<'label'>;
+  /**
+   * Whether this checkbox represents a parent/group checkbox with indeterminate state support.
+   */
+  parent?: boolean;
};
🤖 Prompt for AI Agents
In app/components/ui/checkbox.tsx at line 21, the `parent` prop is used in the
Checkbox component but is missing from the `CheckboxProps` type definition. To
fix this, add a `parent` property with the appropriate type to the
`CheckboxProps` interface to ensure type safety and proper prop validation.

TFIeldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
>(
props: FieldCheckboxGroupProps<TFIeldValues, TName>
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

Fix typo in props type

The props type reference also needs to be corrected.

-  props: FieldCheckboxGroupProps<TFIeldValues, TName>
+  props: FieldCheckboxGroupProps<TFieldValues, TName>
📝 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
props: FieldCheckboxGroupProps<TFIeldValues, TName>
props: FieldCheckboxGroupProps<TFieldValues, TName>
🤖 Prompt for AI Agents
In app/components/form/field-checkbox-group/index.tsx at line 32, there is a
typo in the props type name "TFIeldValues" which should be corrected to
"TFieldValues". Update the type reference to fix the capitalization error to
ensure proper typing.

Comment on lines +15 to +17
export type FieldCheckboxGroupProps<
TFIeldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
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

Fix typo in generic type parameter

There's a typo in the generic type parameter name: TFIeldValues should be TFieldValues.

-export type FieldCheckboxGroupProps<
-  TFIeldValues extends FieldValues = FieldValues,
-  TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
+export type FieldCheckboxGroupProps<
+  TFieldValues extends FieldValues = FieldValues,
+  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
📝 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
export type FieldCheckboxGroupProps<
TFIeldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
export type FieldCheckboxGroupProps<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
🤖 Prompt for AI Agents
In app/components/form/field-checkbox-group/index.tsx around lines 15 to 17, fix
the typo in the generic type parameter by renaming `TFIeldValues` to
`TFieldValues` to ensure consistent and correct naming.

Comment on lines +28 to +31
export const FieldCheckboxGroup = <
TFIeldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
>(
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

Fix typo in generic type parameter

The same typo exists in the component function signature.

-export const FieldCheckboxGroup = <
-  TFIeldValues extends FieldValues = FieldValues,
-  TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
+export const FieldCheckboxGroup = <
+  TFieldValues extends FieldValues = FieldValues,
+  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
📝 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
export const FieldCheckboxGroup = <
TFIeldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFIeldValues> = FieldPath<TFIeldValues>,
>(
export const FieldCheckboxGroup = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>(
🤖 Prompt for AI Agents
In app/components/form/field-checkbox-group/index.tsx around lines 28 to 31,
there is a typo in the generic type parameter name "TFIeldValues" which should
be corrected to "TFieldValues" consistently in the component function signature
to fix the typo.

@ivan-dalmet ivan-dalmet force-pushed the v3-main branch 2 times, most recently from cf02ee7 to cbaf95e Compare July 21, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
components Related to a Start UI custom component enhancement New feature or request v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant