Skip to content

doc(Select): add DefaultVirtualizeItemText parameter sample code#7294

Merged
ArgoZhang merged 4 commits intomainfrom
doc-select
Dec 11, 2025
Merged

doc(Select): add DefaultVirtualizeItemText parameter sample code#7294
ArgoZhang merged 4 commits intomainfrom
doc-select

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 11, 2025

Link issues

fixes #7292

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

Document and demonstrate the use of DefaultVirtualizeItemText in virtualized Select samples while aligning value types with Foo IDs and tightening default item selection logic.

New Features:

  • Add sample usage of DefaultVirtualizeItemText to virtualized Select components using both OnQueryAsync and Items data sources.

Bug Fixes:

  • Correct localized resource keys used in the ConfirmSelect sample descriptions.
  • Align Select value and item value fields to use Foo.Id as the underlying value instead of the display name.
  • Prevent the Select component from defaulting to the first non-disabled row when no active or matching item is found.

Enhancements:

  • Initialize virtualized Select samples with default selected IDs and corresponding display text derived from the data source.

Copilot AI review requested due to automatic review settings December 11, 2025 05:04
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Dec 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the Select component samples to demonstrate DefaultVirtualizeItemText with ID-based values, fixes localization key typos, adjusts virtualized data mappings, and slightly refines default item selection logic in the core Select component.

Updated class diagram for Selects sample component and Select core logic

classDiagram
  class Selects {
    +IEnumerable~SelectedItem~ VirtualItems
    -int? _virtualItem1
    -string? VirtualItemText1
    -int? _virtualItem2
    -string? VirtualItemText2
    -List~Foo~ Foos
    +Task~QueryData~SelectedItem~~ OnQueryAsync(VirtualizeQueryOption option)
  }

  class Foo {
    +int Id
    +string? Name
  }

  class SelectedItem {
    +string? Value
    +string? Text
    +bool Active
    +bool IsDisabled
    SelectedItem(string value, string text)
  }

  class Select {
    -List~SelectedItem~ Rows
    -string? CurrentValueAsString
    +SelectedItem? GetDefaultItem()
    +SelectedItem? GetItemWithEnumValue()
  }

  Selects --> Foo : uses
  Selects --> SelectedItem : builds_virtual_items
  Selects --> Select : used_in_Razor_sample
  Select --> SelectedItem : manages_rows
Loading

File-Level Changes

Change Details Files
Update Select sample to demonstrate DefaultVirtualizeItemText with virtualized data and ID-based values.
  • Change virtualized Select bindings from SelectedItem to int? backing fields to better reflect typical value usage.
  • Introduce DefaultVirtualizeItemText parameters (VirtualItemText1/VirtualItemText2) for virtualized Select examples.
  • Update VirtualItems and OnQueryAsync to use Foo.Id as the SelectedItem.Value instead of the name, aligning with the int? bound values.
  • Adjust Display components to show the bound integer values instead of SelectedItem.Text.
src/BootstrapBlazor.Server/Components/Samples/Selects.razor
src/BootstrapBlazor.Server/Components/Samples/Selects.razor.cs
Fix localization resource key typos used in the Select demo documentation.
  • Correct Select confirmation description resource keys from misspelled names to SelectConfirmSelectDesc1/SelectConfirmSelectDesc2.
  • Ensure locale JSON files contain matching keys for the updated resource names.
src/BootstrapBlazor.Server/Components/Samples/Selects.razor
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
Slightly refine default item selection logic in the Select component.
  • Replace Rows.FirstOrDefault(i => !i.IsDisabled) with Rows.Find(i => !i.IsDisabled) when determining the default selected item, keeping semantics the same while using a consistent list search API.
src/BootstrapBlazor/Components/Select/Select.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7292 Ensure that the Select component correctly displays the item text (not the raw numeric value) when IsVirtualize="true" and the bound Value is an int, i.e., fix the type comparison / selection logic so virtualized and non-virtualized behavior match. The PR mainly updates the demo/sample (Selects.razor and its code-behind) to use int? backing fields, DefaultVirtualizeItemText, and different SelectedItem values, and it adjusts a default-row selection line (Rows.FirstOrDefault -> Rows.Find) in Select.razor.cs. It does not introduce a change that fixes the core type-comparison/display issue for virtualized Select when TValue is int; instead it only documents/illustrates usage of DefaultVirtualizeItemText. The underlying bug described in the issue—that enabling IsVirtualize causes the selected item to display as a number rather than the expected text for int-typed values—is not clearly resolved by these changes.

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

@bb-auto bb-auto Bot added the bug Something isn't working label Dec 11, 2025
@bb-auto bb-auto Bot added this to the v10.1.0 milestone Dec 11, 2025
Copy link
Copy Markdown
Contributor

@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:

  • In Selects.razor.cs, VirtualItemText1 and VirtualItemText2 are hardcoded to Id == 2 and Id == 3; consider deriving these from _virtualItem1 and _virtualItem2 respectively so the displayed text always matches the currently bound value.
  • The new _virtualItem1/_virtualItem2 fields use a naming convention that appears different from the existing VirtualItem* members; consider aligning the naming pattern (fields vs properties) with the rest of the component for consistency and readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Selects.razor.cs`, `VirtualItemText1` and `VirtualItemText2` are hardcoded to `Id == 2` and `Id == 3`; consider deriving these from `_virtualItem1` and `_virtualItem2` respectively so the displayed text always matches the currently bound value.
- The new `_virtualItem1`/`_virtualItem2` fields use a naming convention that appears different from the existing `VirtualItem*` members; consider aligning the naming pattern (fields vs properties) with the rest of the component for consistency and readability.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor.Server/Components/Samples/Selects.razor:455-456` </location>
<code_context>
     <div class="row mb-3">
         <div class="col-6">
-            <Select IsVirtualize="true" OnQueryAsync="OnQueryAsync" @bind-Value="VirtualItem1"
+            <Select IsVirtualize="true" OnQueryAsync="OnQueryAsync" @bind-Value="_virtualItem1"
+                    DefaultVirtualizeItemText="@VirtualItemText1"
                     ShowSearch="_showSearch" IsClearable="_isClearable"></Select>
         </div>
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Keep the default virtual item text derived from the current bound value instead of a hard-coded ID.

`DefaultVirtualizeItemText` is currently based on `Foos.FirstOrDefault(i => i.Id == 2)?.Name`, while the bound value is `_virtualItem1`. If `_virtualItem1`’s default changes (e.g., to 5) but the hard-coded `2` is not updated, the displayed text and selected value will diverge. Please derive the text from `_virtualItem1` (e.g., by using its value in the lookup) so they always stay in sync.

Suggested implementation:

```
    private string? VirtualItemText1 => _virtualItem1.HasValue
        ? Foos.FirstOrDefault(i => i.Id == _virtualItem1.Value)?.Name
        : null;

```

If the property is currently declared with a non-nullable return type (`string` instead of `string?`), adjust the type accordingly or provide a sensible fallback (e.g., `?? string.Empty`). Also ensure that `_virtualItem1` and `Foos` are in scope in this component's code block.
</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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (76809d2) to head (7bdc67f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          745       745           
  Lines        32628     32628           
  Branches      4522      4522           
=========================================
  Hits         32628     32628           
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang ArgoZhang merged commit 24729ef into main Dec 11, 2025
9 of 10 checks passed
@ArgoZhang ArgoZhang deleted the doc-select branch December 11, 2025 05:08
Copy link
Copy Markdown
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 pull request adds sample code demonstrating the DefaultVirtualizeItemText parameter for the Select component when using virtualization. The changes update the virtualization demo to properly show how this parameter works with both OnQueryAsync and Items data sources.

Key changes:

  • Modified virtualization demo to use integer IDs instead of SelectedItem objects for better type safety
  • Added DefaultVirtualizeItemText parameter to both virtualization examples
  • Fixed spelling typos in localization keys (SelectConfirm vs SelectConfifm)
  • Updated Chinese documentation to explain the DefaultVirtualizeItemText parameter usage
  • Changed Select component logic from FirstOrDefault to Find for consistency

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Select.razor.cs Changed method from FirstOrDefault to Find for consistent pattern usage when selecting non-disabled items
zh-CN.json Fixed typo in localization keys (SelectConfirm vs SelectConfifm) and added documentation about DefaultVirtualizeItemText parameter
en-US.json Fixed typo in localization keys (SelectConfirm vs SelectConfifm)
Selects.razor.cs Updated virtualization demo to use integer IDs, added properties for default virtualized item text, and modified data source to use Foo.Id instead of Foo.Name
Selects.razor Added DefaultVirtualizeItemText parameter to both virtualization examples and updated Display components to show integer values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"SelectsVirtualizeTitle": "虚拟滚动",
"SelectsVirtualizeIntro": "通过设置 <code>IsVirtualize</code> 参数开启组件虚拟功能特性",
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据",
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据。如果数据源使用 <code>OnQueryAsync</code> 回调获得时只有当下拉框展开时才会触发,,如果数据源使用 <code>Items</code> 时,由于性能问题(有些开发会把几百万条数据给 Items)内部并没有进行查找选中项,所以需要设置 <code>DefaultVirtualizeItemText</code> 值应对首次加载时不知道如何显示问题",
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

There is a double comma (,,) in the Chinese text. It should be a single comma.

Suggested change
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据。如果数据源使用 <code>OnQueryAsync</code> 回调获得时只有当下拉框展开时才会触发,如果数据源使用 <code>Items</code> 时,由于性能问题(有些开发会把几百万条数据给 Items)内部并没有进行查找选中项,所以需要设置 <code>DefaultVirtualizeItemText</code> 值应对首次加载时不知道如何显示问题",
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据。如果数据源使用 <code>OnQueryAsync</code> 回调获得时只有当下拉框展开时才会触发,如果数据源使用 <code>Items</code> 时,由于性能问题(有些开发会把几百万条数据给 Items)内部并没有进行查找选中项,所以需要设置 <code>DefaultVirtualizeItemText</code> 值应对首次加载时不知道如何显示问题",

Copilot uses AI. Check for mistakes.
Comment on lines +455 to 457
<Select IsVirtualize="true" OnQueryAsync="OnQueryAsync" @bind-Value="_virtualItem1"
DefaultVirtualizeItemText="@VirtualItemText1"
ShowSearch="_showSearch" IsClearable="_isClearable"></Select>
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The Select component is missing the TValue generic parameter specification. While type inference may work in some cases, it's best practice to explicitly declare TValue for clarity and to avoid potential type inference issues. Consider adding TValue="int?" to match the binding type.

Copilot uses AI. Check for mistakes.
<div class="row">
<div class="col-6">
<Select IsVirtualize="true" Items="VirtualItems" @bind-Value="VirtualItem2"
<Select IsVirtualize="true" Items="VirtualItems" @bind-Value="_virtualItem2"
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The Select component is missing the TValue generic parameter specification. While type inference may work in some cases, it's best practice to explicitly declare TValue for clarity and to avoid potential type inference issues. Consider adding TValue="int?" to match the binding type.

Suggested change
<Select IsVirtualize="true" Items="VirtualItems" @bind-Value="_virtualItem2"
<Select TValue="int?" IsVirtualize="true" Items="VirtualItems" @bind-Value="_virtualItem2"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(Select): IsVirtualize="true" make the type comparison failed

2 participants