Skip to content

feat(BootstrapInputGroupLabel): add IToolbarComponent cascading value#7259

Merged
ArgoZhang merged 3 commits intomainfrom
feat-label
Dec 5, 2025
Merged

feat(BootstrapInputGroupLabel): add IToolbarComponent cascading value#7259
ArgoZhang merged 3 commits intomainfrom
feat-label

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 5, 2025

Link issues

fixes #7258

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

Support toolbar components as input group labels and ensure they receive necessary cascading values.

New Features:

  • Allow BootstrapInputGroupLabel to detect and behave as an input group label when used within a toolbar component via a cascading IToolbarComponent value.

Tests:

  • Add a unit test verifying BootstrapInputGroupLabel renders correctly when provided with a cascading IToolbarComponent value.

Copilot AI review requested due to automatic review settings December 5, 2025 06:46
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Dec 5, 2025

Reviewer's Guide

Adds cascading of the IToolbarComponent into BootstrapInputGroupLabel so it can act as an input group label inside table toolbars, updates TableToolbar cascading values accordingly, and introduces a unit test validating the new behavior.

Sequence diagram for cascading IToolbarComponent into BootstrapInputGroupLabel

sequenceDiagram
participant TableToolbar
participant TableToolbarComponent_TItem_ as TableToolbarComponent
participant BootstrapInputGroupLabel

TableToolbar->>TableToolbarComponent_TItem_: Render when IsShow is true
TableToolbarComponent_TItem_->>BootstrapInputGroupLabel: Render ChildContent
activate TableToolbarComponent_TItem_
TableToolbarComponent_TItem_-->>BootstrapInputGroupLabel: CascadingParameter ToolbarComponent = button
TableToolbarComponent_TItem_-->>BootstrapInputGroupLabel: CascadingParameter OnGetSelectedRows
BootstrapInputGroupLabel->>BootstrapInputGroupLabel: Compute IsInputGroupLabel
BootstrapInputGroupLabel-->>TableToolbarComponent_TItem_: Render output based on IsInputGroupLabel
deactivate TableToolbarComponent_TItem_
Loading

Class diagram for BootstrapInputGroupLabel with IToolbarComponent cascading

classDiagram
class BootstrapInputGroupLabel {
    +string? Value
    +bool? IsGroupLabel
    +bool ShowRequiredMark
    +string? Required
    +bool IsInputGroupLabel
}

class InputGroup

class IToolbarComponent {
    <<interface>>
    +bool IsShow
}

class TableToolbarComponent_TItem_ {
    +bool IsShow
}

BootstrapInputGroupLabel --> InputGroup : CascadingParameter InputGroup
BootstrapInputGroupLabel --> IToolbarComponent : CascadingParameter ToolbarComponent
TableToolbarComponent_TItem_ ..|> IToolbarComponent
Loading

Flow diagram for IsInputGroupLabel evaluation with ToolbarComponent

flowchart TD
    A[Start IsInputGroupLabel evaluation] --> B{IsGroupLabel has value}
    B -->|yes| C[IsInputGroupLabel = IsGroupLabel]
    B -->|no| D{InputGroup is not null or ToolbarComponent is not null}
    D -->|yes| E[IsInputGroupLabel = true]
    D -->|no| F[IsInputGroupLabel = false]
    C --> G[End]
    E --> G
    F --> G
Loading

File-Level Changes

Change Details Files
Allow BootstrapInputGroupLabel to detect when it is used inside a toolbar component via a cascading IToolbarComponent and treat itself as an input-group label.
  • Add a private cascading parameter of type IToolbarComponent? to BootstrapInputGroupLabel.
  • Extend the IsInputGroupLabel condition to also be true when a ToolbarComponent is present.
src/BootstrapBlazor/Components/Input/BootstrapInputGroupLabel.cs
Cascade the toolbar button component itself into its child content and preserve the existing cascading of OnGetSelectedRows.
  • Wrap TableToolbarComponent child content in a CascadingValue providing the toolbar button instance.
  • Nest the existing CascadingValue for OnGetSelectedRows inside the new CascadingValue so both values are available to descendants.
src/BootstrapBlazor/Components/Table/TableToolbar.razor
Add a unit test ensuring BootstrapInputGroupLabel behaves as an input-group label when an IToolbarComponent is cascaded.
  • Render BootstrapInputGroupLabel within a CascadingValue using a mock toolbar component.
  • Assert that the rendered markup contains the input-group-text CSS class.
  • Introduce a simple MockToolbarComponent implementing IToolbarComponent for testing.
test/UnitTest/Components/InputTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7258 Add an IToolbarComponent cascading parameter/value to BootstrapInputGroupLabel so it can receive toolbar context via CascadingParameter.
#7258 Update BootstrapInputGroupLabel logic to treat the presence of an IToolbarComponent cascading value as making it act as an input group label.

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 enhancement New feature or request label Dec 5, 2025
@bb-auto bb-auto bot added this to the v10.1.0 milestone Dec 5, 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:

  • The IsInputGroupLabel expression combines ?? and || without parentheses; given C#’s operator precedence this may not evaluate as intended, so consider explicitly grouping it as IsGroupLabel ?? (InputGroup != null || ToolbarComponent != null) (or similar) to make the logic unambiguous.
  • In TableToolbar.razor, the cascading value currently uses Value="button" inside the else if (button is TableToolbarComponent<TItem> { IsShow: true } cb) block; using cb instead of button would be clearer and ensures the cascaded value is explicitly the TableToolbarComponent<TItem> instance.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `IsInputGroupLabel` expression combines `??` and `||` without parentheses; given C#’s operator precedence this may not evaluate as intended, so consider explicitly grouping it as `IsGroupLabel ?? (InputGroup != null || ToolbarComponent != null)` (or similar) to make the logic unambiguous.
- In `TableToolbar.razor`, the cascading value currently uses `Value="button"` inside the `else if (button is TableToolbarComponent<TItem> { IsShow: true } cb)` block; using `cb` instead of `button` would be clearer and ensures the cascaded value is explicitly the `TableToolbarComponent<TItem>` instance.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/TableToolbar.razor:37` </location>
<code_context>
                     {
-                        <CascadingValue Value="OnGetSelectedRows" IsFixed="true">
-                            @cb.ChildContent
+                        <CascadingValue Value="button" IsFixed="true">
+                            <CascadingValue Value="OnGetSelectedRows" IsFixed="true">
+                                @cb.ChildContent
+                            </CascadingValue>
</code_context>

<issue_to_address>
**issue (bug_risk):** Consider cascading `cb` (or an explicit `IToolbarComponent` cast) instead of `button` to avoid mismatched cascading type.

Because `button` is likely typed as a broader interface/base type (the collection element type), `<CascadingValue>` will infer that broader type for the cascade. That value may not be assignable to `IToolbarComponent`, so it might not reach `BootstrapInputGroupLabel`’s `IToolbarComponent` cascade parameter. Using `cb` (typed as `TableToolbarComponent<TItem>`) or an explicit `IToolbarComponent` cast keeps the cascaded type aligned with the consumer and avoids this mismatch.
</issue_to_address>

### Comment 2
<location> `test/UnitTest/Components/InputTest.cs:298-299` </location>
<code_context>
         cut.Contains("input-group-text");
     }

+    [Fact]
+    public void ToolbarComponent_Ok()
+    {
+        var cut = Context.Render<CascadingValue<IToolbarComponent>>(pb =>
</code_context>

<issue_to_address>
**suggestion (testing):** Add a complementary test to cover the case where a ToolbarComponent is present but IsGroupLabel is explicitly set to false.

Given the new `IsInputGroupLabel` logic (`IsGroupLabel ?? InputGroup != null || ToolbarComponent != null`), we should verify that an explicit `IsGroupLabel = false` still suppresses the `input-group-text` styling when a `ToolbarComponent` is cascaded.

A test like this would cover that override behavior and help catch regressions if the boolean expression changes:

```csharp
[Fact]
public void ToolbarComponent_WithIsGroupLabelFalse_DoesNotRenderGroupLabel()
{
    var cut = Context.Render<CascadingValue<IToolbarComponent>>(pb =>
    {
        pb.Add(a => a.Value, new MockToolbarComponent());
        pb.Add(a => a.IsFixed, true);
        pb.Add(a => a.ChildContent, builder =>
        {
            builder.OpenComponent<BootstrapInputGroupLabel>(0);
            builder.AddAttribute(1, nameof(BootstrapInputGroupLabel.IsGroupLabel), false);
            builder.CloseComponent();
        });
    });

    cut.DoesNotContain("input-group-text");
}
```
</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.

@ArgoZhang ArgoZhang enabled auto-merge (squash) December 5, 2025 06:48
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 5, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7259   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          745       745           
  Lines        32585     32586    +1     
  Branches      4516      4516           
=========================================
+ Hits         32585     32586    +1     
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 ba29cfa into main Dec 5, 2025
9 of 10 checks passed
@ArgoZhang ArgoZhang deleted the feat-label branch December 5, 2025 06:49
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 PR enhances the BootstrapInputGroupLabel component to support automatic styling when used within toolbar contexts by adding IToolbarComponent cascading parameter support. This allows labels within TableToolbarComponent to automatically apply the input-group-text CSS class without requiring manual configuration.

  • Adds IToolbarComponent cascading parameter to BootstrapInputGroupLabel
  • Updates TableToolbar.razor to cascade the toolbar button component instance
  • Includes comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/BootstrapBlazor/Components/Input/BootstrapInputGroupLabel.cs Adds IToolbarComponent cascading parameter and updates logic to check for toolbar component presence when determining label styling
src/BootstrapBlazor/Components/Table/TableToolbar.razor Wraps TableToolbarComponent child content with additional cascading value to pass button instance; removes BOM character from file
test/UnitTest/Components/InputTest.cs Adds ToolbarComponent_Ok test with mock implementation to verify cascading parameter functionality
src/BootstrapBlazor/BootstrapBlazor.csproj Bumps version from 10.1.1 to 10.1.2-beta01

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

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(BootstrapInputGroupLabel): add IToolbarComponent cascading value

2 participants