diff --git a/Havit.Blazor.Components.Web.Bootstrap/ContextMenus/HxContextMenuItem.razor b/Havit.Blazor.Components.Web.Bootstrap/ContextMenus/HxContextMenuItem.razor index 1efb7104d..b422ed7ea 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/ContextMenus/HxContextMenuItem.razor +++ b/Havit.Blazor.Components.Web.Bootstrap/ContextMenus/HxContextMenuItem.razor @@ -6,12 +6,12 @@ }
  • - - @if (this.Icon is not null) - { - - } - @this.Text - @ChildContent - + + @if (this.Icon is not null) + { + + } + @this.Text + @ChildContent +
  • diff --git a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleButton.cs b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleButton.cs index 696f03a08..3c1b763b2 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleButton.cs +++ b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleButton.cs @@ -62,6 +62,7 @@ static HxDropdownToggleButton() /// The parameter can be used to override the settings of the component or to specify the auto-close behavior when the component is not used. /// [Parameter] public DropdownAutoClose? AutoClose { get; set; } + protected DropdownAutoClose AutoCloseEffective => AutoClose ?? DropdownContainer?.AutoClose ?? DropdownAutoClose.True; [CascadingParameter] protected HxDropdown DropdownContainer { get; set; } [CascadingParameter] protected HxNav NavContainer { get; set; } @@ -99,13 +100,13 @@ protected override void OnParametersSet() AdditionalAttributes ??= new Dictionary(); AdditionalAttributes["data-bs-toggle"] = "dropdown"; AdditionalAttributes["aria-expanded"] = "false"; - AdditionalAttributes["data-bs-auto-close"] = (AutoClose ?? DropdownContainer?.AutoClose ?? DropdownAutoClose.True) switch + AdditionalAttributes["data-bs-auto-close"] = AutoCloseEffective switch { DropdownAutoClose.True => "true", DropdownAutoClose.False => "false", DropdownAutoClose.Inside => "inside", DropdownAutoClose.Outside => "outside", - _ => throw new InvalidOperationException($"Unknown {nameof(DropdownAutoClose)} value {AutoClose ?? DropdownContainer.AutoClose}.") + _ => throw new InvalidOperationException($"Unknown {nameof(DropdownAutoClose)} value {AutoCloseEffective}.") }; if (this.DropdownOffset is not null) diff --git a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleElement.cs b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleElement.cs index ecdc223cc..b59fbc721 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleElement.cs +++ b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/HxDropdownToggleElement.cs @@ -37,6 +37,15 @@ public class HxDropdownToggleElement : ComponentBase, IHxDropdownToggle, IAsyncD /// [Parameter] public string CssClass { get; set; } + /// + /// By default, the dropdown menu is closed when clicking inside or outside the dropdown menu (). + /// You can use the AutoClose parameter to change this behavior of the dropdown. + /// https://getbootstrap.com/docs/5.3/components/dropdowns/#auto-close-behavior. + /// The parameter can be used to override the settings of the component or to specify the auto-close behavior when the component is not used. + /// + [Parameter] public DropdownAutoClose? AutoClose { get; set; } + protected DropdownAutoClose AutoCloseEffective => AutoClose ?? DropdownContainer?.AutoClose ?? DropdownAutoClose.True; + [Parameter] public RenderFragment ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] public IDictionary AdditionalAttributes { get; set; } @@ -86,13 +95,13 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddAttribute(1, "data-bs-toggle", "dropdown"); builder.AddAttribute(2, "aria-expanded", "false"); - var dataBsAutoCloseAttributeValue = (DropdownContainer?.AutoClose ?? DropdownAutoClose.True) switch + var dataBsAutoCloseAttributeValue = AutoCloseEffective switch { DropdownAutoClose.True => "true", DropdownAutoClose.False => "false", DropdownAutoClose.Inside => "inside", DropdownAutoClose.Outside => "outside", - _ => throw new InvalidOperationException($"Unknown {nameof(DropdownAutoClose)} value {DropdownContainer.AutoClose}.") + _ => throw new InvalidOperationException($"Unknown {nameof(DropdownAutoClose)} value {AutoCloseEffective}.") }; builder.AddAttribute(3, "data-bs-auto-close", dataBsAutoCloseAttributeValue); diff --git a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/IHxDropdownToggle.cs b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/IHxDropdownToggle.cs index 4497cf51e..d3a422f4a 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/IHxDropdownToggle.cs +++ b/Havit.Blazor.Components.Web.Bootstrap/Dropdowns/IHxDropdownToggle.cs @@ -9,6 +9,8 @@ internal interface IHxDropdownToggle string DropdownReference { get; set; } EventCallback OnHidden { get; set; } EventCallback OnShown { get; set; } + DropdownAutoClose? AutoClose { get; set; } + Task HandleJsHidden(); Task HandleJsShown();