Skip to content

fix: update multi-select to use value prop for dynamic defaults #18982

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

blink-so[bot]
Copy link
Contributor

@blink-so blink-so bot commented Jul 21, 2025

contributes to coder/internal#753

Summary

Fixes issue where multi-select parameters don't update their selected values when dynamic defaults change.

Changes

  • Changed MultiSelectCombobox in DynamicParameter to use value prop instead of defaultOptions
  • This ensures the component properly reacts to parameter value changes when other parameters trigger dynamic updates

Problem

When using dynamic parameters with multi-select form types, changing one parameter (like git_repo) that affects the defaults of another multi-select parameter (like ides) would not update the selected values in the UI. The form state would update correctly, but the UI would show stale selected options.

Root Cause

The MultiSelectCombobox component was using defaultOptions prop which only sets initial state. When the parent component updates the selected options due to dynamic parameter changes, the component wasn't reacting to these changes.

Solution

Using the value prop instead of defaultOptions makes the component controlled and reactive to parent state changes. The MultiSelectCombobox already has logic to handle value updates:

const [previousValue, setPreviousValue] = useState<Option[]>(value || []);
if (value && value !== previousValue) {
    setPreviousValue(value);
    setSelected(value);
}

Testing

This change maintains the same API and behavior for static parameters while fixing the dynamic update issue. The component will now properly update selected values when the parent provides new values.

Fixes coder/internal#753

blink-so bot and others added 3 commits July 21, 2025 23:27
Fixes issue where multi-select parameters don't update their selected
values when dynamic defaults change. Changed from using defaultOptions
to value prop in MultiSelectCombobox to ensure proper reactivity.

Fixes coder/internal#753

Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
Ensures that when using the value prop (controlled mode), the component
properly initializes with the provided selected options on first render.

Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
@jaaydenh jaaydenh requested a review from Emyrk July 23, 2025 16:23
blink-so bot and others added 4 commits July 23, 2025 16:25
Ensures that when using the value prop (controlled mode), the component
properly initializes with the provided selected options on first render.
This was reverted in the previous commit but is needed for the fix.

Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
Replaces the problematic reference comparison with proper useEffect
to handle controlled value prop updates. This ensures that when the
value prop changes, the selected state is properly updated.

Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
@jaaydenh jaaydenh self-assigned this Jul 23, 2025
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.

Dynamic defaults seem to not update on Multi-select in coder/coder
1 participant