Skip to content

fix(Suggestion): preserve controlled input value - #5200

Open
olemartinorg wants to merge 1 commit into
digdir:mainfrom
olemartinorg:codex/fix-controlled-suggestion-input
Open

fix(Suggestion): preserve controlled input value#5200
olemartinorg wants to merge 1 commit into
digdir:mainfrom
olemartinorg:codex/fix-controlled-suggestion-input

Conversation

@olemartinorg

@olemartinorg olemartinorg commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Keep a controlled Suggestion input synchronized with its accepted selected prop when a consumer defers or rejects a proposed selection.

The single-selection synchronization added in #5043 writes the proposed option label directly into the input before calling onSelectedChange. For controlled consumers, this makes the visible input disagree with selected until the parent accepts the change. Consumers that deliberately defer acceptance—for example, to ask for confirmation—can then receive a follow-up empty selection while the component reconciles.

This was discovered in Altinn/altinn-studio#19766 while upgrading Altinn Studio to Designsystemet 1.18.0/1.19.0. Altinn's Dropdown waits for confirmation before updating selected; after confirmation, Suggestion emitted an empty change and reopened the confirmation popover with an empty option label.

The existing selected-item reconciliation already updates the input when the controlled prop changes. This removes the premature write and adds React-wrapper tests for both rejected/deferred proposals and accepted prop updates.

Verification

  • Confirmed the controlled-proposal regression test fails before the fix with Expected: Norway, Received: Sweden.
  • React Suggestion browser tests: 2 passed in Chromium.
  • Existing web Suggestion tests: 9 passed across Chromium, Firefox, and WebKit.
  • Biome passed for the changed React source and test.

Suggestion writes proposed single selections directly into its input before a
controlled parent accepts them. Consumers that defer or reject changes therefore show
state that disagrees with their selected prop and can emit a follow-up empty selection
while reconciling.

Let the existing selected-item reconciliation update the input after the parent accepts
a value. Cover both deferred selections and accepted prop updates so controlled state
remains authoritative without losing input synchronization.
@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ef5825

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@digdir/designsystemet-react Patch
@digdir/designsystemet Patch
@digdir/designsystemet-css Patch
@digdir/designsystemet-types Patch
@digdir/designsystemet-web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@olemartinorg
olemartinorg marked this pull request as ready for review August 14, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant