Repository navigation
[checkbox group] Fix uncontrolled default initialization - #4535
Conversation
Bundle size report
Check out the code infra dashboard for more information about this PR. |
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| const disabled = fieldDisabled || disabledProp; | ||
|
|
||
| const [value, setValueUnwrapped] = useControlled({ | ||
| const defaultValue = React.useMemo<string[] | undefined>(() => { |
There was a problem hiding this comment.
Would that work?
| const defaultValue = React.useMemo<string[] | undefined>(() => { | |
| const defaultValue = externalValue === undefined | |
| ? (defaultValueProp ?? EMPTY_ARRAY) | |
| : undefined |
There was a problem hiding this comment.
It's used as a dependency, so it has to be wrapped in memo (EMPTY_ARRAY is not really safe to use here)
1791569 to
70c2aa8
Compare
Codex Review (GPT-5.4)I reviewed the full branch diff against a freshly fetched 1. Bugs / Issues (None)Root Cause & Patch AssessmentThe main fix in The follow-up change in Pattern Consistency AssessmentThe final shape is consistent with the rest of the controlled/uncontrolled patterns in this codebase: initialize the uncontrolled source once in I also checked the nearby parent-checkbox flow in Test Coverage AssessmentCoverage is proportionate to the risk. The new regression in I also ran RecommendationApprove ✅ I do not see any actionable issues remaining in the current branch. The patch now fixes the uncontrolled initialization bug at the correct layer, preserves the parent-checkbox ownership model, and includes targeted regression coverage for both affected paths. |
An uncontrolled
CheckboxGroupwithoutvalueordefaultValueshould behave like an empty selected list, but it could fall back to per-checkbox local state instead of maintaining a shared group value. This initializes the uncontrolled group value to[]so the checkbox group state behaves consistently from the first render.Changes
CheckboxGroupstate to an empty array when nodefaultValueis provided.defaultValuecheckbox-group case.