diff --git a/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor b/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor index 71a55356052..9a564769028 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor @@ -37,7 +37,7 @@
- +
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs index a47abc52468..5e51ff48194 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Dropdowns.razor.cs @@ -251,6 +251,18 @@ private AttributeItem[] GetAttributes() => /// private EventItem[] GetEvents() => [ + new() + { + Name = "OnClick", + Description = Localizer["EventDesc1"], + Type ="EventCallback" + }, + new() + { + Name = "OnClickWithoutRender", + Description = Localizer["EventDesc2"], + Type ="Func" + }, new EventItem() { Name = "OnSelectedItemChanged", diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 2f985a9ef14..43afeeb8947 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -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", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 0f3fca089e3..a4e851896d0 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -1793,6 +1793,8 @@ "AttributeButtonTemplate": "按钮模板", "AttributeItemTemplate": "菜单项模板", "AttributeItemsTemplate": "下拉菜单模板", + "EventDesc1": "点击按钮时触发此事件", + "EventDesc2": "点击按钮时触发此事件并且不刷新当前组件,用于提高性能时使用", "EventOnSelectedItemChanged": "下拉框值发生改变时触发", "FixedButtonText": "固定按钮显示文字", "Item1": "北京", diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor index 26b69d56ad4..5df35546499 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor @@ -8,7 +8,8 @@ }
- + @if (ShowSplit) { diff --git a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs index 69848af544a..bf9e226662d 100644 --- a/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs +++ b/src/BootstrapBlazor/Components/Dropdown/Dropdown.razor.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Microsoft.AspNetCore.Components.Web; + namespace BootstrapBlazor.Components; /// @@ -102,6 +104,18 @@ public partial class Dropdown [Parameter] public bool ShowSplit { get; set; } + /// + /// 获得/设置 OnClick 事件 + /// + [Parameter] + public EventCallback OnClick { get; set; } + + /// + /// 获得/设置 OnClick 事件不刷新父组件 + /// + [Parameter] + public Func? OnClickWithoutRender { get; set; } + /// /// 获得/设置 获取菜单对齐方式 默认 none 未设置 /// @@ -203,4 +217,16 @@ protected async Task OnItemClick(SelectedItem item) } private string? ButtonText => IsFixedButtonText ? FixedButtonText : SelectedItem?.Text; + + private async Task OnClickButton() + { + if (OnClickWithoutRender != null) + { + await OnClickWithoutRender(); + } + if (OnClick.HasDelegate) + { + await OnClick.InvokeAsync(); + } + } }