Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Dropdown TValue="string" Items="Items" ShowSplit="true" Color="Color.Primary"></Dropdown>
</div>
<div class="col-6 col-sm-4 col-md-3">
<Dropdown TValue="string" Items="Items" ShowSplit="false" Color="Color.Info"></Dropdown>
<Dropdown TValue="string" Items="Items" ShowSplit="true" Color="Color.Info"></Dropdown>
</div>
<div class="col-6 col-sm-4 col-md-3">
<Dropdown TValue="string" Items="Items" ShowSplit="true" Color="Color.Warning"></Dropdown>
Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ private AttributeItem[] GetAttributes() =>
/// <returns></returns>
private EventItem[] GetEvents() =>
[
new()
{
Name = "OnClick",
Description = Localizer["EventDesc1"],
Type ="EventCallback<MouseEventArgs>"
},
new()
{
Name = "OnClickWithoutRender",
Description = Localizer["EventDesc2"],
Type ="Func<Task>"
},
new EventItem()
{
Name = "OnSelectedItemChanged",
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@
"AttributeButtonTemplate": "The template of button",
"AttributeItemTemplate": "The template of item",
"AttributeItemsTemplate": "The template of items",
"EventDesc1": "This event is triggered when the button is clicked",
"EventDesc2": "This event is triggered when the button is clicked and the current component is not refreshed for performance improvement",
"EventOnSelectedItemChanged": "Triggered when the value of the drop-down box changes",
"FixedButtonText": "The text of fixed button",
"Item1": "Melbourne",
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@
"AttributeButtonTemplate": "按钮模板",
"AttributeItemTemplate": "菜单项模板",
"AttributeItemsTemplate": "下拉菜单模板",
"EventDesc1": "点击按钮时触发此事件",
"EventDesc2": "点击按钮时触发此事件并且不刷新当前组件,用于提高性能时使用",
"EventOnSelectedItemChanged": "下拉框值发生改变时触发",
"FixedButtonText": "固定按钮显示文字",
"Item1": "北京",
Expand Down
5 changes: 3 additions & 2 deletions src/BootstrapBlazor/Components/Dropdown/Dropdown.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<BootstrapLabel for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="@AdditionalAttributes" id="@Id" class="@DirectionClassName">
<button type="button" class="@ButtonClassName" data-bs-toggle="@DropdownToggle" disabled="@Disabled">
<DynamicElement type="button" class="@ButtonClassName" data-bs-toggle="@DropdownToggle" disabled="@Disabled"
TriggerClick="ShowSplit" OnClick="OnClickButton">
@if (ButtonTemplate == null)
{
@ButtonText
Expand All @@ -17,7 +18,7 @@
{
@ButtonTemplate(SelectedItem)
}
</button>
</DynamicElement>
@if (ShowSplit)
{
<button type="button" class="@ClassName" data-bs-toggle="@ToggleString" disabled="@Disabled" aria-haspopup="true" aria-expanded="false"></button>
Expand Down
26 changes: 26 additions & 0 deletions src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using Microsoft.AspNetCore.Components.Web;

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -102,6 +104,18 @@ public partial class Dropdown<TValue>
[Parameter]
public bool ShowSplit { get; set; }

/// <summary>
/// 获得/设置 OnClick 事件
/// </summary>
[Parameter]
public EventCallback<MouseEventArgs> OnClick { get; set; }

/// <summary>
/// 获得/设置 OnClick 事件不刷新父组件
/// </summary>
[Parameter]
public Func<Task>? OnClickWithoutRender { get; set; }

/// <summary>
/// 获得/设置 获取菜单对齐方式 默认 none 未设置
/// </summary>
Expand Down Expand Up @@ -203,4 +217,16 @@ protected async Task OnItemClick(SelectedItem item)
}

private string? ButtonText => IsFixedButtonText ? FixedButtonText : SelectedItem?.Text;

private async Task OnClickButton()
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Event callback handler signature may be missing MouseEventArgs parameter.

Since the OnClick parameter is of type EventCallback, consider updating OnClickButton to accept a MouseEventArgs parameter (e.g. OnClickButton(MouseEventArgs e)) and passing it to OnClick.InvokeAsync(e). This ensures that any event data provided by the underlying click event is not lost.

{
if (OnClickWithoutRender != null)
{
await OnClickWithoutRender();
}
if (OnClick.HasDelegate)
{
await OnClick.InvokeAsync();
}
}
}
Loading