Skip to content

fix(checkbox): pass form prop to checkbox #4979

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

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

smozely
Copy link
Contributor

@smozely smozely commented Mar 4, 2025

📝 Description

Fixes an issue where the checkbox component couldn't be used when passing a form as a prop. which works for the other components exposed from Hero UI

⛳️ Current behavior (updates)

the form prop passed to a checkbox component was just silently dropped.

🚀 New behavior

the form prop passed to a checkbox component is now passed down to the input component. Followed the same pattern that was used for the <Input> component of using filterDOMProps

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Same idea as #4854

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Checkbox component now supports associating with a specific form via a new form property.
  • Tests
    • Added a test case to verify the correct application of the form attribute in the Checkbox component.

@smozely smozely requested a review from jrgarciadev as a code owner March 4, 2025 20:27
Copy link

changeset-bot bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: abf5fac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@heroui/checkbox Patch
@heroui/table Patch
@heroui/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 4, 2025

@smozely is attempting to deploy a commit to the HeroUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

A patch is applied to the @heroui/checkbox package as indicated in the changeset entry. The update involves passing a form property to the checkbox component. Additionally, the useCheckbox hook’s getInputProps function has been modified to conditionally include the form property based on the presence of otherProps.form, and the dependency array for the useCallback hook has been updated.

Changes

File(s) Change Summary
.changeset/smart-cats-walk.md Added a new changeset entry indicating a patch for the @heroui/checkbox package, noting that a form property will be passed to the component.
packages/components/checkbox/src/use-checkbox.ts Modified the getInputProps function in the useCheckbox hook to conditionally include the form property and updated the dependency array for useCallback to include otherProps.
packages/components/checkbox/__tests__/checkbox.test.tsx Added a test case to verify the functionality of the "form" prop in the Checkbox component, ensuring the input element has the correct "form" attribute when rendered with a specific value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure the form attribute is passed down to the <input> element of the Checkbox (#5439)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related issues

  • [BUG] - InputProps on Checkbox are passed to label, not to input #5510: The main issue modifies the getInputProps function in use-checkbox.ts to conditionally include a form property in the input props, while the retrieved issue reports a bug where inputProps are incorrectly passed to the label instead of the input element; since the main issue changes the input props composition and the retrieved issue concerns the correct application of input props, these changes are related at the code level in managing input properties within the checkbox component.

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between feaff1f and abf5fac.

📒 Files selected for processing (1)
  • .changeset/smart-cats-walk.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/smart-cats-walk.md
⏰ 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). (4)
  • GitHub Check: Continuous Release
  • GitHub Check: Build
  • GitHub Check: ESLint
  • GitHub Check: TypeScript
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

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

pkg-pr-new bot commented Mar 4, 2025

Open in StackBlitz

@heroui/accordion

npm i https://pkg.pr.new/@heroui/accordion@4979

@heroui/alert

npm i https://pkg.pr.new/@heroui/alert@4979

@heroui/autocomplete

npm i https://pkg.pr.new/@heroui/autocomplete@4979

@heroui/avatar

npm i https://pkg.pr.new/@heroui/avatar@4979

@heroui/badge

npm i https://pkg.pr.new/@heroui/badge@4979

@heroui/breadcrumbs

npm i https://pkg.pr.new/@heroui/breadcrumbs@4979

@heroui/button

npm i https://pkg.pr.new/@heroui/button@4979

@heroui/calendar

npm i https://pkg.pr.new/@heroui/calendar@4979

@heroui/card

npm i https://pkg.pr.new/@heroui/card@4979

@heroui/checkbox

npm i https://pkg.pr.new/@heroui/checkbox@4979

@heroui/chip

npm i https://pkg.pr.new/@heroui/chip@4979

@heroui/code

npm i https://pkg.pr.new/@heroui/code@4979

@heroui/date-input

npm i https://pkg.pr.new/@heroui/date-input@4979

@heroui/date-picker

npm i https://pkg.pr.new/@heroui/date-picker@4979

@heroui/divider

npm i https://pkg.pr.new/@heroui/divider@4979

@heroui/drawer

npm i https://pkg.pr.new/@heroui/drawer@4979

@heroui/dropdown

npm i https://pkg.pr.new/@heroui/dropdown@4979

@heroui/form

npm i https://pkg.pr.new/@heroui/form@4979

@heroui/image

npm i https://pkg.pr.new/@heroui/image@4979

@heroui/input

npm i https://pkg.pr.new/@heroui/input@4979

@heroui/input-otp

npm i https://pkg.pr.new/@heroui/input-otp@4979

@heroui/kbd

npm i https://pkg.pr.new/@heroui/kbd@4979

@heroui/link

npm i https://pkg.pr.new/@heroui/link@4979

@heroui/listbox

npm i https://pkg.pr.new/@heroui/listbox@4979

@heroui/menu

npm i https://pkg.pr.new/@heroui/menu@4979

@heroui/modal

npm i https://pkg.pr.new/@heroui/modal@4979

@heroui/navbar

npm i https://pkg.pr.new/@heroui/navbar@4979

@heroui/number-input

npm i https://pkg.pr.new/@heroui/number-input@4979

@heroui/pagination

npm i https://pkg.pr.new/@heroui/pagination@4979

@heroui/popover

npm i https://pkg.pr.new/@heroui/popover@4979

@heroui/progress

npm i https://pkg.pr.new/@heroui/progress@4979

@heroui/radio

npm i https://pkg.pr.new/@heroui/radio@4979

@heroui/ripple

npm i https://pkg.pr.new/@heroui/ripple@4979

@heroui/scroll-shadow

npm i https://pkg.pr.new/@heroui/scroll-shadow@4979

@heroui/select

npm i https://pkg.pr.new/@heroui/select@4979

@heroui/skeleton

npm i https://pkg.pr.new/@heroui/skeleton@4979

@heroui/slider

npm i https://pkg.pr.new/@heroui/slider@4979

@heroui/snippet

npm i https://pkg.pr.new/@heroui/snippet@4979

@heroui/spacer

npm i https://pkg.pr.new/@heroui/spacer@4979

@heroui/spinner

npm i https://pkg.pr.new/@heroui/spinner@4979

@heroui/switch

npm i https://pkg.pr.new/@heroui/switch@4979

@heroui/table

npm i https://pkg.pr.new/@heroui/table@4979

@heroui/tabs

npm i https://pkg.pr.new/@heroui/tabs@4979

@heroui/toast

npm i https://pkg.pr.new/@heroui/toast@4979

@heroui/tooltip

npm i https://pkg.pr.new/@heroui/tooltip@4979

@heroui/user

npm i https://pkg.pr.new/@heroui/user@4979

@heroui/react

npm i https://pkg.pr.new/@heroui/react@4979

@heroui/system

npm i https://pkg.pr.new/@heroui/system@4979

@heroui/system-rsc

npm i https://pkg.pr.new/@heroui/system-rsc@4979

@heroui/theme

npm i https://pkg.pr.new/@heroui/theme@4979

@heroui/use-aria-accordion

npm i https://pkg.pr.new/@heroui/use-aria-accordion@4979

@heroui/use-aria-accordion-item

npm i https://pkg.pr.new/@heroui/use-aria-accordion-item@4979

@heroui/use-aria-button

npm i https://pkg.pr.new/@heroui/use-aria-button@4979

@heroui/use-aria-link

npm i https://pkg.pr.new/@heroui/use-aria-link@4979

@heroui/use-aria-modal-overlay

npm i https://pkg.pr.new/@heroui/use-aria-modal-overlay@4979

@heroui/use-aria-multiselect

npm i https://pkg.pr.new/@heroui/use-aria-multiselect@4979

@heroui/use-aria-overlay

npm i https://pkg.pr.new/@heroui/use-aria-overlay@4979

@heroui/use-callback-ref

npm i https://pkg.pr.new/@heroui/use-callback-ref@4979

@heroui/use-clipboard

npm i https://pkg.pr.new/@heroui/use-clipboard@4979

@heroui/use-data-scroll-overflow

npm i https://pkg.pr.new/@heroui/use-data-scroll-overflow@4979

@heroui/use-disclosure

npm i https://pkg.pr.new/@heroui/use-disclosure@4979

@heroui/use-draggable

npm i https://pkg.pr.new/@heroui/use-draggable@4979

@heroui/use-form-reset

npm i https://pkg.pr.new/@heroui/use-form-reset@4979

@heroui/use-image

npm i https://pkg.pr.new/@heroui/use-image@4979

@heroui/use-infinite-scroll

npm i https://pkg.pr.new/@heroui/use-infinite-scroll@4979

@heroui/use-intersection-observer

npm i https://pkg.pr.new/@heroui/use-intersection-observer@4979

@heroui/use-is-mobile

npm i https://pkg.pr.new/@heroui/use-is-mobile@4979

@heroui/use-is-mounted

npm i https://pkg.pr.new/@heroui/use-is-mounted@4979

@heroui/use-measure

npm i https://pkg.pr.new/@heroui/use-measure@4979

@heroui/use-pagination

npm i https://pkg.pr.new/@heroui/use-pagination@4979

@heroui/use-real-shape

npm i https://pkg.pr.new/@heroui/use-real-shape@4979

@heroui/use-ref-state

npm i https://pkg.pr.new/@heroui/use-ref-state@4979

@heroui/use-resize

npm i https://pkg.pr.new/@heroui/use-resize@4979

@heroui/use-safe-layout-effect

npm i https://pkg.pr.new/@heroui/use-safe-layout-effect@4979

@heroui/use-scroll-position

npm i https://pkg.pr.new/@heroui/use-scroll-position@4979

@heroui/use-ssr

npm i https://pkg.pr.new/@heroui/use-ssr@4979

@heroui/use-theme

npm i https://pkg.pr.new/@heroui/use-theme@4979

@heroui/use-update-effect

npm i https://pkg.pr.new/@heroui/use-update-effect@4979

@heroui/use-viewport-size

npm i https://pkg.pr.new/@heroui/use-viewport-size@4979

@heroui/aria-utils

npm i https://pkg.pr.new/@heroui/aria-utils@4979

@heroui/dom-animation

npm i https://pkg.pr.new/@heroui/dom-animation@4979

@heroui/framer-utils

npm i https://pkg.pr.new/@heroui/framer-utils@4979

@heroui/react-rsc-utils

npm i https://pkg.pr.new/@heroui/react-rsc-utils@4979

@heroui/react-utils

npm i https://pkg.pr.new/@heroui/react-utils@4979

@heroui/shared-icons

npm i https://pkg.pr.new/@heroui/shared-icons@4979

@heroui/shared-utils

npm i https://pkg.pr.new/@heroui/shared-utils@4979

@heroui/stories-utils

npm i https://pkg.pr.new/@heroui/stories-utils@4979

@heroui/test-utils

npm i https://pkg.pr.new/@heroui/test-utils@4979

commit: abf5fac

@smozely smozely force-pushed the fix/checkbox_form_link branch 2 times, most recently from f42d4a4 to feaff1f Compare March 5, 2025 08:31
Comment on lines +315 to +325
...(otherProps.form ? {form: otherProps.form} : {}),
};
}, [inputProps, focusProps, handleCheckboxChange, classNames?.hiddenInput]);
}, [inputProps, focusProps, handleCheckboxChange, classNames?.hiddenInput, otherProps]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was unsure how best to do this, originally I tried using filterDOMProps like is used in the input. But that ended up including other props which were already being passed to the <Label> that gets created by this component.

Surprised that this isn't coming through from the useCheckbox from react-aria

Copy link
Member

Choose a reason for hiding this comment

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

In < Input/>, does form only exist in input and not in base? I think this PR's change only cover form prop and there should be other cases.

Copy link
Contributor Author

@smozely smozely Aug 10, 2025

Choose a reason for hiding this comment

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

Ah sorry missed the notification for this comment.

Yeah I guess what I mean from my comment, is it felt like this should probably use filterDomProps but I was unsure of what props should be passed to filterDomProps.

i.e. should it match packages/components/input/src/use-input.ts which has this ...

          filterDOMProps(otherProps, {
            enabled: true,
            labelable: true,
            omitEventNames: new Set(Object.keys(inputProps)),
          }),

Which seemed like it was potentially passing a lot more things down to the DOM element, which might be the right thing to do, but I was little worried there would be some unknown prop that shouldn't be passed.

So I put this PR up with just what I had done to get it working, basically to get the conversation started

@smozely smozely force-pushed the fix/checkbox_form_link branch from feaff1f to abf5fac Compare August 10, 2025 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Form ID is not passed to checkbox input
2 participants