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

Add indeterminate prop to the Checkbox #1415

Merged
merged 14 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: changes indeterminate stories args
  • Loading branch information
long-lazuli authored and connor-baer committed May 24, 2023
commit fc3a0b5944e2af3d62788d42fb28af523e4dea03
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ Indeterminate.args = {
'name': 'indeterminate',
'value': 'any value',
'aria-checked': 'mixed',
'indeterminate': true,
};
5 changes: 3 additions & 2 deletions packages/circuit-ui/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
}

localRef.current.indeterminate = indeterminate;
}, [indeterminate]);
// Because it came from a props, we are keeping the `indeterminate` state even if the `checked` one is changed:
}, [props.defaultChecked, props.checked, indeterminate]);

return (
<CheckboxWrapper className={className} style={style} disabled={disabled}>
Expand All @@ -275,7 +276,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
type="checkbox"
disabled={disabled}
invalid={invalid}
ref={applyMultipleRefs(localRef, passedRef)}
ref={applyMultipleRefs(passedRef, localRef)}
aria-describedby={descriptionIds}
onChange={handleChange}
{...(indeterminate && { 'aria-checked': 'mixed' })}
Expand Down