Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Nov 1, 2025

Link issues

fixes #7045

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

Add ItemsTemplate support to the Dropdown component by introducing a new DropdownItem component for customizable items, update styling and sample page, and extend tests for the new functionality

New Features:

  • Add ItemsTemplate parameter to Dropdown to allow custom item rendering
  • Introduce new DropdownItem component with icon, text, disabled state, and click callback

Enhancements:

  • Support fixed button text for Dropdown via IsFixedButtonText and FixedButtonText parameters
  • Improve dropdown-menu styling by adding spacing for dividers

Documentation:

  • Add ItemsTemplate usage example in the Dropdown sample page with demo of custom item actions

Tests:

  • Refactor DropdownTest to asynchronously test ItemsTemplate including disabled state and click events
  • Simplify OnClickWithoutRender setup in tests

Copilot AI review requested due to automatic review settings November 1, 2025 08:44
@bb-auto bb-auto bot added the enhancement New feature or request label Nov 1, 2025
@bb-auto bb-auto bot added this to the 10.0.0 milestone Nov 1, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 1, 2025

Reviewer's Guide

Implements an ItemsTemplate parameter in the Dropdown component to allow fully customizable item rendering through a new DropdownItem component; updates the rendering logic and styling, extends unit tests to cover the new behavior, and adds a demo in the sample pages with an accompanying click handler.

Sequence diagram for Dropdown with ItemsTemplate and DropdownItem click

sequenceDiagram
    actor User
    participant Dropdown
    participant DropdownItem
    participant ToastService
    User->>Dropdown: Clicks dropdown button
    Dropdown->>DropdownItem: Renders custom items via ItemsTemplate
    User->>DropdownItem: Clicks item
    DropdownItem->>DropdownItem: Checks IsDisabled
    DropdownItem->>DropdownItem: Calls OnClickItem()
    DropdownItem->>ToastService: Executes OnClick callback
    ToastService-->>User: Shows notification
Loading

Class diagram for new DropdownItem component and updated Dropdown

classDiagram
class DropdownItem {
  +string? Text
  +string? Icon
  +bool Disabled
  +Func<bool>? OnDisabledCallback
  +Func<Task>? OnClick
  +RenderFragment? ChildContent
  -string? ItemIconString
  -string? ItemClassString
  -bool IsDisabled
  -Task OnClickItem()
}
class Dropdown {
  +RenderFragment? ItemsTemplate
  -List<ComponentBase> _items
}
Dropdown "1" o-- "*" DropdownItem : uses via ItemsTemplate
Loading

File-Level Changes

Change Details Files
Support custom item templates in Dropdown component
  • Add ItemsTemplate parameter and render it when provided
  • Refactor split-button markup formatting for consistency
  • Introduce SCSS rules for dropdown dividers
src/BootstrapBlazor/Components/Dropdown/Dropdown.razor
src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.scss
src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs
Introduce DropdownItem component
  • Define Text, Icon, Disabled, OnClick and OnDisabledCallback parameters
  • Implement ChildContent or default icon/text rendering
  • Compose CSS classes dynamically for icon and disabled state
src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor
src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor.cs
Enhance unit tests for ItemsTemplate
  • Simplify OnClickWithoutRender lambda syntax
  • Add an async ItemsTemplate_Ok test covering rendering, disabled states and click events
test/UnitTest/Components/DropdownTest.cs
Add demo and handler for ItemsTemplate in samples
  • Insert a new DemoBlock using ItemsTemplate with DropdownItem and Divider
  • Implement OnClickAction method in sample code-behind
src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor
src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7045 Add an ItemsTemplate parameter to the Dropdown component to allow custom rendering of dropdown items.
#7045 Implement a DropdownItem component to support custom item rendering, including properties such as Text, Icon, Disabled, OnDisabledCallback, OnClick, and ChildContent.
#7045 Update documentation and sample/demo code to demonstrate usage of the new ItemsTemplate parameter in the Dropdown component.

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

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Nov 1, 2025
Copy link
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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor.cs:57` </location>
<code_context>
+        .AddClass("disabled", IsDisabled)
+        .Build();
+
+    private bool IsDisabled => OnDisabledCallback?.Invoke() ?? Disabled;
+
+    private async Task OnClickItem()
</code_context>

<issue_to_address>
**issue (bug_risk):** OnDisabledCallback may throw if it throws an exception.

Wrap OnDisabledCallback.Invoke() in a try/catch to prevent exceptions from disrupting dropdown rendering.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/Dropdown/DropdownItem.razor:11-15` </location>
<code_context>
+{
+    <DynamicElement class="@ItemClassString"
+                    TriggerClick="!IsDisabled" OnClick="OnClickItem">
+        <i class="@ItemIconString"></i>
+        <span>@Text</span>
+    </DynamicElement>
</code_context>

<issue_to_address>
**suggestion:** Rendering an empty <i> element if Icon is not set.

Consider rendering the <i> element only when Icon is provided to prevent unnecessary empty elements in the DOM.

```suggestion
    <DynamicElement class="@ItemClassString"
                    TriggerClick="!IsDisabled" OnClick="OnClickItem">
        @if (!string.IsNullOrEmpty(ItemIconString))
        {
            <i class="@ItemIconString"></i>
        }
        <span>@Text</span>
    </DynamicElement>
```
</issue_to_address>

### Comment 3
<location> `test/UnitTest/Components/DropdownTest.cs:325-332` </location>
<code_context>
+        cut.Contains("fa-solid fa-icon3");
+        cut.Contains("dropdown-item-test3");
+
+        cut.DoesNotContain("fa-solid fa-icon4");
+        cut.DoesNotContain("dropdown-item-test4");
+        cut.Contains("dropdown-item-childcontent");
+
+        cut.Contains("dropdown-item disabled");
</code_context>

<issue_to_address>
**suggestion (testing):** Suggestion to add explicit assertions for disabled item click behavior.

Add an assertion to confirm that clicking a disabled DropdownItem does not trigger its OnClick handler or change the 'clicked' state.

```suggestion
        cut.Contains("dropdown-item disabled");

        Assert.False(clicked);

        // Find the disabled dropdown item and try to click it
        var disabledItem = cut.Find(".dropdown-item.disabled");
        await cut.InvokeAsync(() => disabledItem.Click());
        // Assert that clicking the disabled item does not change the clicked state
        Assert.False(clicked);

        var item = cut.Find(".dropdown-item:not(.disabled)");
        await cut.InvokeAsync(() => item.Click());
        Assert.True(clicked);
    }
```
</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

codecov bot commented Nov 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2f53676) to head (12a6c59).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7046   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          743       745    +2     
  Lines        32480     32515   +35     
  Branches      4500      4506    +6     
=========================================
+ Hits         32480     32515   +35     
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.

@ArgoZhang ArgoZhang merged commit 1905435 into main Nov 1, 2025
7 checks passed
@ArgoZhang ArgoZhang deleted the feat-dropdown branch November 1, 2025 08:56
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(Dropdown): add ItemsTemplate parameter

2 participants