Stop a validation checkbox from flipping the switch above it - #209
Merged
Conversation
Ticking "Allow CSV" or "Allow JSON" in the admin panel turned data
validation off and collapsed the block the checkbox lives in. The
researcher's click did the opposite of what it said, and the setting it
silently changed decides whether malformed submissions are rejected.
The cause was an id collision, not anything in the validation logic. Ark
derives a control's hidden-input id from the surrounding Field context --
`useSwitch` and `useCheckbox` both do `ids: { hiddenInput:
field?.ids.control, label: field?.ids.label }`. SettingsRow rendered its
`children` inside the row's own `Field.Root`, so both checkboxes were
handed the SAME DOM id as the master switch's hidden input.
`Checkbox.Root` is itself a `<label htmlFor={thatId}>`, and the browser
resolves a label to the FIRST element carrying that id -- the switch,
which renders above. So the click activated the switch.
The Field now wraps only the switch and its label; `SaveError` and
`children` move out to an enclosing Stack. Dependent controls elsewhere
(the numeric inputs in ExperimentActive, the required-fields input) each
open their own `Field.Root` already, so they were never affected and are
unaffected by this -- only controls that INHERITED the row's field were
broken by it, which is why the fix belongs in SettingsRow rather than in
any one call site.
Tests click the labels, not the inputs: clicking an input directly never
went through the broken path, so a test that does that passes either way.
Three of the new cases fail against the previous SettingsRow.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SHZNijLwUhn26yCbYbn1UN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
In
/admin/<experiment>, ticking Allow CSV or Allow JSON turned data validation off and collapsed the block the checkbox lives in. The click did the opposite of what it said, and the setting it silently changed is the one that decides whether malformed submissions are rejected before they reach the researcher's storage provider.Cause
An id collision, not anything in the validation logic.
Ark derives a control's hidden-input id from the surrounding Field context —
useSwitchanduseCheckboxboth do:SettingsRowrendered itschildreninside the row's ownField.Root, so both checkboxes were handed the same DOM id as the master switch's hidden input.Checkbox.Rootis itself a<label htmlFor={thatId}>, and the browser resolves a label to the first element in the document carrying that id — the switch, which renders above. So clicking the checkbox activated the switch.Fix
The
Field.Rootnow wraps only the switch and its label/description;SaveErrorandchildrenmove out to an enclosingStack.Dependent controls elsewhere (the numeric inputs in
ExperimentActive, the required-fields input inExperimentValidation) each open their ownField.Rootalready, so they were never affected and stay unaffected. Only controls that inherited the row's field were broken by it — which is why the fix belongs inSettingsRowrather than in any one call site.Tests
Five cases added to
__tests__/experiment-validation.test.jsx. They click the labels, not the inputs: clicking an input directly never went through the broken path, so a test that does that passes either way. Three of the five fail against the previousSettingsRowand pass now.🤖 Generated with Claude Code
https://claude.ai/code/session_01SHZNijLwUhn26yCbYbn1UN