Skip to content

Commit feaff1f

Browse files
committed
fix(checkbox): pass form prop to checkbox
1 parent 9a95a71 commit feaff1f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changeset/smart-cats-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@heroui/checkbox": patch
3+
---
4+
5+
Pass form prop to checkbox

packages/components/checkbox/__tests__/checkbox.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ describe("Checkbox", () => {
143143
expect(onChange).toHaveBeenCalled();
144144
});
145145

146+
it('should work correctly with "form" prop', () => {
147+
const wrapper = render(
148+
<Checkbox data-testid="checkbox-test" form="test-form-id">
149+
Option
150+
</Checkbox>,
151+
);
152+
153+
expect(wrapper.container.querySelector("input")).toHaveAttribute("form", "test-form-id");
154+
});
155+
146156
describe("validation", () => {
147157
describe("validationBehavior=native", () => {
148158
it("supports isRequired", async () => {

packages/components/checkbox/src/use-checkbox.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ export function useCheckbox(props: UseCheckboxProps = {}) {
312312
...mergeProps(inputProps, focusProps),
313313
className: slots.hiddenInput({class: classNames?.hiddenInput}),
314314
onChange: chain(inputProps.onChange, handleCheckboxChange),
315+
...(otherProps.form ? {form: otherProps.form} : {}),
315316
};
316-
}, [inputProps, focusProps, handleCheckboxChange, classNames?.hiddenInput]);
317+
}, [inputProps, focusProps, handleCheckboxChange, classNames?.hiddenInput, otherProps]);
317318

318319
const getLabelProps: PropGetter = useCallback(
319320
() => ({

0 commit comments

Comments
 (0)