Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 9, 2025

Fixes #11255

Summary

This PR implements automatic default value selection for InputType.Choice inputs when no placeholder is specified and custom choices are not allowed. When a Choice input doesn't have a placeholder text and AllowCustomChoice is false, it now defaults to the first option's value, providing a better user experience by ensuring a valid selection is always present.

Changes

Core Implementation

Modified InputViewModel.SetInput() in src/Aspire.Dashboard/Model/Interaction/InputViewModel.cs to automatically set the value to the first option when:

  • Input type is Choice
  • Options are available (not null/empty)
  • No placeholder is set
  • Current value is empty
  • AllowCustomChoice is false (ensures strict selection from provided options)
// If no placeholder is set and value is empty, default to the first option
// Only default when AllowCustomChoice is false to ensure strict selection from options
if (string.IsNullOrEmpty(input.Placeholder) && string.IsNullOrEmpty(input.Value) && optionsVM.Count > 0 && !input.AllowCustomChoice)
{
    input.Value = optionsVM[0].Id;
}

Test Coverage

Added comprehensive test suite in tests/Aspire.Dashboard.Components.Tests/Model/InputViewModelTests.cs covering:

  • Choice input without placeholder → defaults to first option ✅
  • Choice input with placeholder → remains empty ✅
  • Choice input with existing value → preserves existing value ✅
  • Choice input with AllowCustomChoice=true → remains empty ✅
  • Edge cases (empty/null options, non-choice inputs) ✅
  • SetInput method behavior ✅

Demo Command

Added a test command in playground/Stress/Stress.AppHost/InteractionCommands.cs named "Choice with no placeholder" that demonstrates the functionality with two inputs:

  • Dinner choice (no placeholder, AllowCustomChoice=false) - defaults to "pizza"
  • Requirements choice (no placeholder, AllowCustomChoice=true) - remains empty

This allows manual testing and verification of the feature in the Stress playground.

Behavior

Before:

var input = new InteractionInput
{
    InputType = InputType.Choice,
    Options = [KeyValuePair.Create("red", "Red"), KeyValuePair.Create("blue", "Blue")]
};
var vm = new InputViewModel(input);
// vm.Value was empty string

After (AllowCustomChoice = false, default):

var input = new InteractionInput
{
    InputType = InputType.Choice,
    Options = [KeyValuePair.Create("red", "Red"), KeyValuePair.Create("blue", "Blue")]
};
var vm = new InputViewModel(input);
// vm.Value is now "red" (first option)

With Placeholder (unchanged):

var input = new InteractionInput
{
    InputType = InputType.Choice,
    Placeholder = "Select a color",
    Options = [KeyValuePair.Create("red", "Red"), KeyValuePair.Create("blue", "Blue")]
};
var vm = new InputViewModel(input);
// vm.Value remains empty (placeholder shown)

With AllowCustomChoice = true (no default):

var input = new InteractionInput
{
    InputType = InputType.Choice,
    AllowCustomChoice = true,
    Options = [KeyValuePair.Create("red", "Red"), KeyValuePair.Create("blue", "Blue")]
};
var vm = new InputViewModel(input);
// vm.Value remains empty (allows user to enter custom value)

Testing

  • ✅ All new tests pass (9 tests)
  • ✅ All Dashboard.Components.Tests pass (82 tests)
  • ✅ All Dashboard.Tests pass (880 tests)
  • ✅ Stress.AppHost builds successfully
  • ✅ Full solution builds successfully
Original prompt

When the interaction service is used, an input is InputType.Choice, and it doesn't have a placeholder, the input's value should default to the first option's value.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Set default value for Choice input in interaction service Default Choice inputs to first option when no placeholder is set Oct 9, 2025
Copilot AI requested a review from JamesNK October 9, 2025 05:50
Copilot finished work on behalf of JamesNK October 9, 2025 05:50
@JamesNK
Copy link
Member

JamesNK commented Oct 9, 2025

@copilot Additionally, only default to the first option if the type is choice and AllowCustomChoice is false.

@JamesNK
Copy link
Member

JamesNK commented Oct 9, 2025

@copilot Cherry pick changes from commit 408dc5d into PR

Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot Additionally, only default to the first option if the type is choice and AllowCustomChoice is false.

Added the AllowCustomChoice check in commit 3c7b0d8. Now the default value is only set when AllowCustomChoice is false, ensuring that inputs allowing custom values retain their flexibility.

Copilot AI changed the title Default Choice inputs to first option when no placeholder is set Default Choice inputs to first option when no placeholder is set and custom choice is disabled Oct 9, 2025
Copilot finished work on behalf of JamesNK October 9, 2025 06:02
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot Cherry pick changes from commit 408dc5d into PR

Cherry-picked commit 408dc5d in bae849c. This adds a test command "Choice with no placeholder" to the Stress playground that demonstrates the functionality with two inputs:

  • Dinner choice (no placeholder, AllowCustomChoice=false) - defaults to "pizza"
  • Requirements choice (no placeholder, AllowCustomChoice=true) - remains empty

Copilot finished work on behalf of JamesNK October 9, 2025 06:11
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11918

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11918"

@JamesNK JamesNK marked this pull request as ready for review October 9, 2025 06:15
Copilot AI review requested due to automatic review settings October 9, 2025 06:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements automatic default value selection for Choice inputs in the Aspire Dashboard interaction service. When a Choice input has no placeholder and doesn't allow custom choices, it now defaults to the first available option, improving user experience by ensuring a valid selection is always present.

Key Changes

  • Modified InputViewModel.SetInput() to automatically set Choice inputs to the first option when conditions are met
  • Added comprehensive test coverage with 9 new test cases covering various scenarios
  • Added a demo command in the Stress playground to demonstrate the functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Dashboard/Model/Interaction/InputViewModel.cs Core logic implementation for defaulting Choice inputs to first option
tests/Aspire.Dashboard.Components.Tests/Model/InputViewModelTests.cs Comprehensive test suite covering all scenarios and edge cases
playground/Stress/Stress.AppHost/InteractionCommands.cs Demo command for manual testing of the new functionality
Comments suppressed due to low confidence (1)

tests/Aspire.Dashboard.Components.Tests/Model/InputViewModelTests.cs:1

  • The title and message don't match the actual functionality. The title says 'Text request' and message says 'Provide your name' but this is testing choice inputs for dinner selection.
// Licensed to the .NET Foundation under one or more agreements.

@JamesNK JamesNK requested review from adamint and mitchdenny October 9, 2025 06:24
Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested in codespaces.

@JamesNK JamesNK force-pushed the copilot/default-choice-input-value branch from 939b356 to 5318cf1 Compare October 13, 2025 01:21
@JamesNK JamesNK enabled auto-merge (squash) October 13, 2025 01:24
@JamesNK JamesNK merged commit b4b1da6 into main Oct 13, 2025
302 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using the interaction service and InputType.Choice the first options is not actually selected by default

3 participants