Skip to content

fix(SelectCity): reset Value after update IsMultiple parameter#614

Merged
ArgoZhang merged 2 commits intomasterfrom
fix-city
Oct 18, 2025
Merged

fix(SelectCity): reset Value after update IsMultiple parameter#614
ArgoZhang merged 2 commits intomasterfrom
fix-city

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Oct 18, 2025

Link issues

fixes #613

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Reset selected values and improve active styling when toggling multiple selection in SelectCity component

Bug Fixes:

  • Clear selected values when IsMultiple is false
  • Update GetActiveClass to distinguish between single and multiple selection modes for active styling

Copilot AI review requested due to automatic review settings October 18, 2025 09:22
@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 18, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Oct 18, 2025
@ArgoZhang ArgoZhang merged commit 0a27a19 into master Oct 18, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the fix-city branch October 18, 2025 09:22
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refines the SelectCity component so that its selection state and CSS “active” styling correctly reflect the IsMultiple parameter, and it updates the project file to include these changes.

Class diagram for updated SelectCity component

classDiagram
    class SelectCity {
        - string? _searchText
        - List<string> _values
        - bool IsMultiple
        - string? CurrentValue
        + string? GetActiveClass(string item)
        + void OnParametersSet()
    }
    SelectCity : GetActiveClass(string item)
    SelectCity : OnParametersSet()
Loading

Flow diagram for selection state reset based on IsMultiple parameter

flowchart TD
    A[OnParametersSet called] --> B{IsMultiple}
    B -- Yes --> C[Keep _values as is]
    B -- No --> D[Clear _values]
Loading

File-Level Changes

Change Details Files
Separated active CSS class logic for single vs. multiple selection
  • Apply “active” only when item is in _values and IsMultiple is true
  • Apply “active” when CurrentValue equals item and IsMultiple is false
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs
Reset internal value list when switching to single-select mode
  • In OnParametersSet, clear _values if IsMultiple is false
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs
Updated project configuration to include the component fix
  • Refresh BootstrapBlazor.Region.csproj to reflect the latest component changes
src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#613 Fix SelectCity to reset Value after updating the IsMultiple parameter.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

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 fixes a bug in the SelectCity component where the value state wasn't properly reset when switching between single and multiple selection modes. The fix ensures that when IsMultiple is false, the internal _values collection is cleared to prevent conflicts between single and multiple selection behaviors.

  • Updates the active class logic to handle single vs multiple selection modes correctly
  • Adds value clearing logic when switching from multiple to single selection mode
  • Increments the package version to reflect the fix

Reviewed Changes

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

File Description
SelectCity.razor.cs Fixes active class logic and adds value clearing for single selection mode
BootstrapBlazor.Region.csproj Updates package version from 9.0.5 to 9.0.6

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +56 to +57
.AddClass("active", _values.Contains(item) && IsMultiple)
.AddClass("active", CurrentValue == item && !IsMultiple)
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

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

The two separate AddClass calls for the same CSS class 'active' could be combined into a single call with a more readable condition. Consider: .AddClass('active', (IsMultiple && _values.Contains(item)) || (!IsMultiple && CurrentValue == item))

Suggested change
.AddClass("active", _values.Contains(item) && IsMultiple)
.AddClass("active", CurrentValue == item && !IsMultiple)
.AddClass("active", (IsMultiple && _values.Contains(item)) || (!IsMultiple && CurrentValue == item))

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • You can simplify the GetActiveClass logic by merging the two AddClass calls into one conditional (e.g. .AddClass("active", IsMultiple ? _values.Contains(item) : CurrentValue == item)) for improved readability.
  • To avoid losing the last selected city when switching back to multiple mode, consider populating _values with the current single CurrentValue when IsMultiple changes from false to true.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You can simplify the GetActiveClass logic by merging the two AddClass calls into one conditional (e.g. `.AddClass("active", IsMultiple ? _values.Contains(item) : CurrentValue == item)`) for improved readability.
- To avoid losing the last selected city when switching back to multiple mode, consider populating `_values` with the current single `CurrentValue` when `IsMultiple` changes from false to true.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs:70-72` </location>
<code_context>

         SearchIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectSearchIcon);
+
+        if (!IsMultiple)
+        {
+            _values.Clear();
+        }
     }
</code_context>

<issue_to_address>
**issue (bug_risk):** Clearing _values on every parameter set may unintentionally remove user selections.

Clearing _values each time may erase user selections if OnParametersSet runs multiple times. Consider restricting this to cases where IsMultiple transitions from true to false.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +70 to +72
if (!IsMultiple)
{
_values.Clear();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Clearing _values on every parameter set may unintentionally remove user selections.

Clearing _values each time may erase user selections if OnParametersSet runs multiple times. Consider restricting this to cases where IsMultiple transitions from true to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Region): bump version 9.0.6

2 participants