Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis 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 componentclassDiagram
class SelectCity {
- string? _searchText
- List<string> _values
- bool IsMultiple
- string? CurrentValue
+ string? GetActiveClass(string item)
+ void OnParametersSet()
}
SelectCity : GetActiveClass(string item)
SelectCity : OnParametersSet()
Flow diagram for selection state reset based on IsMultiple parameterflowchart TD
A[OnParametersSet called] --> B{IsMultiple}
B -- Yes --> C[Keep _values as is]
B -- No --> D[Clear _values]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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.
| .AddClass("active", _values.Contains(item) && IsMultiple) | ||
| .AddClass("active", CurrentValue == item && !IsMultiple) |
There was a problem hiding this comment.
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))
| .AddClass("active", _values.Contains(item) && IsMultiple) | |
| .AddClass("active", CurrentValue == item && !IsMultiple) | |
| .AddClass("active", (IsMultiple && _values.Contains(item)) || (!IsMultiple && CurrentValue == item)) |
There was a problem hiding this comment.
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
_valueswith the current singleCurrentValuewhenIsMultiplechanges 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (!IsMultiple) | ||
| { | ||
| _values.Clear(); |
There was a problem hiding this comment.
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.
Link issues
fixes #613
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Reset selected values and improve active styling when toggling multiple selection in SelectCity component
Bug Fixes: