Skip to content

Commit

Permalink
Enhancement for #600 created
Browse files Browse the repository at this point in the history
Added parameter AutoClose and used with higher priority then container one to create data-bs-auto-close attribute
  • Loading branch information
TPIvan committed Oct 20, 2023
1 parent 16aa466 commit ecedbba
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ static HxDropdownToggleButton()
/// </summary>
protected virtual Task InvokeOnHiddenAsync() => OnHidden.InvokeAsync();

/// <summary>
/// By default, the dropdown menu is closed when clicking inside or outside the dropdown menu (<see cref="DropdownAutoClose.True"/>).
/// You can use the AutoClose parameter to change this behavior of the dropdown.
/// <see href="https://getbootstrap.com/docs/5.3/components/dropdowns/#auto-close-behavior">https://getbootstrap.com/docs/5.3/components/dropdowns/#auto-close-behavior</see>.
/// The parameter can be used to override the settings of the <see cref="DropdownContainer"/> component or to specify the auto-close behavior when the component is not used.
/// </summary>
[Parameter] public DropdownAutoClose? AutoClose { get; set; }

[CascadingParameter] protected HxDropdown DropdownContainer { get; set; }
[CascadingParameter] protected HxNav NavContainer { get; set; }

Expand Down Expand Up @@ -91,13 +99,13 @@ protected override void OnParametersSet()
AdditionalAttributes ??= new Dictionary<string, object>();
AdditionalAttributes["data-bs-toggle"] = "dropdown";
AdditionalAttributes["aria-expanded"] = "false";
AdditionalAttributes["data-bs-auto-close"] = (DropdownContainer?.AutoClose ?? DropdownAutoClose.True) switch
AdditionalAttributes["data-bs-auto-close"] = (AutoClose ?? DropdownContainer?.AutoClose ?? DropdownAutoClose.True) 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 {AutoClose ?? DropdownContainer.AutoClose}.")
};

if (this.DropdownOffset is not null)
Expand Down

0 comments on commit ecedbba

Please sign in to comment.