Skip to content
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

[Checkbox] Support form attribute #2484

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/react/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(
defaultChecked,
required,
disabled,
form,
value = 'on',
onCheckedChange,
...checkboxProps
Expand All @@ -56,7 +57,7 @@ const Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
const hasConsumerStoppedPropagationRef = React.useRef(false);
// We set this to true by default so that events bubble to forms without JS (SSR)
const isFormControl = button ? Boolean(button.closest('form')) : true;
const isFormControl = button ? Boolean(button.form) : true;
const [checked = false, setChecked] = useControllableState({
prop: checkedProp,
defaultProp: defaultChecked,
Expand All @@ -82,6 +83,7 @@ const Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(
data-state={getState(checked)}
data-disabled={disabled ? '' : undefined}
disabled={disabled}
form={form}
value={value}
{...checkboxProps}
ref={composedRefs}
Expand Down Expand Up @@ -109,6 +111,7 @@ const Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(
checked={checked}
required={required}
disabled={disabled}
form={form}
// We transform because the input is absolutely positioned but we have
// rendered it **after** the button. This pulls it back to sit on top
// of the button.
Expand Down