Repository navigation
fix(ui): drive the location card's checked state from the form state - #574
Merged
Merged
Conversation
LocationCard kept its checked state in useState(defaultChecked), which is read only on mount. A reset from the header title, or a location set in the store without a click (as a prefilled link does), left the card showing the old state, and the next click was ignored because the card and the store disagreed. The card is now controlled: QueryLocation passes isChecked from form.queryLocation and the card only reports 'add' or 'remove'. The card click handler decides from form.queryLocation too, the list the cards show, and updates the selections by value.
WilhelmZA
approved these changes
Nov 21, 2026
WilhelmZA
left a comment
Collaborator
There was a problem hiding this comment.
Approving at bd5fd0c2.
LocationCard no longer keeps its own state. It renders isChecked from form.queryLocation, and a click calls onChange once with remove or add. handleCardChange now decides from form.queryLocation, which is what the cards show, and adds or removes the selection by value. The card has one caller and both call sites are updated; the select mode is unchanged. The branch contains current main, CI gate passes and the commit is verified. Closes #549 fits.
#567 carries this commit, so this PR should merge first.
Nits:
components/looking-glass-form.test.tsx: "shows the store in the location select too" also passes onmain, so it guards the select mode but not this change. A word in the test name or the body would make that clear.- The body has a Changelog entry but
CHANGELOG.mdis not edited. Please add it under[Unreleased], here or in the release PR.
This was referenced Nov 21, 2026
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.
Problem
LocationCardkept its checked state inuseState(defaultChecked).defaultCheckedis read only on mount, so the card didn't followform.queryLocationonce the form was mounted:The location select (dropdown mode) doesn't have this problem: it is already controlled by
selections.queryLocation.Change
location-card.tsx: the card is controlled.defaultCheckedbecomesisChecked, the local state is removed, and a click callsonChange('remove' | 'add', option)once, from theisCheckedit was given. The card rendersdata-checked, so tests can read its state (it had no other way to show it than the border colour).query-location.tsx: passesisChecked={form.queryLocation.includes(opt.value)}.handleCardChangedecides whether the location is selected fromform.queryLocation, the list the cards show, instead ofselections.queryLocation, and, when adding, drops any existing selection with that value before appending it. Removing works as before. Otherwise a location inform.queryLocationbut not inselectionswould show as selected and ignore the click.Tests
New in
components/looking-glass-form.test.tsx(LookingGlassForm location cards):form.queryLocationandselections.queryLocationare selected (the test from A location card stays selected after a reset and needs two clicks #549);form.queryLocationis set directly; the cards follow it, and one click removes a location;formandselectionsset together, asprefillFormin feat(ui): fill in the query form from URL parameters #567 does;New
components/location-card.test.tsx: shows theisCheckedit is given; a click callsonChangeexactly once withaddorremove, and the card doesn't change by itself.Changed: "does not show the errors from before a reset on the next query" chose Router Three after the reset, with the comment "a card keeps its own checked state across a reset". It now chooses Router One again.
Without the fix (
origin/main's two components, with onlydata-checkedadded so the tests can read the card), four form tests fail on the behaviour: the two below, the prefill-style test and the changed reset test (excerpt):Mutation runs on the final tests (
components/looking-glass-form.test.tsxandcomponents/location-card.test.tsx):data-checkedkept)Tests 7 failed | 33 passed (40)(the 3 card unit tests, the 3 new form tests, the changed reset test)handleCardChangedeciding fromselections.queryLocationTests 1 failed | 39 passed (40)(shows the locations selected in the store without a click)With the fix:
biome format,biome lintandtsc --noEmitpass;Test Files 32 passed (32),Tests 254 passed (254).Changelog
Notes
divwith anonClick, withoutrole="checkbox",aria-checkedor atabIndex, so a card can't be reached with Tab or announced as selected. Gallery mode can't be used without a pointer. This is the same onmainand is tracked in Location cards and the select target aren't keyboard or screen reader accessible #573.Closes #549