Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HxDropdown toggle button add auto close parameter to control the closing behavior #600 #632

Merged
merged 6 commits into from
Oct 24, 2023
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
hakenr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
}

<li class="@CssClassHelper.Combine("hx-context-menu-item", this.CssClass)">
<a class="@CssClassHelper.Combine("dropdown-item", enabledEffective ? "" : "disabled")" role="@(enabledEffective ? "button" : "")" href="@Href" @onclick="HandleClick" @onclick:stopPropagation="@OnClickStopPropagation">
@if (this.Icon is not null)
{
<HxIcon Icon="this.Icon" CssClass="@CssClassHelper.Combine("hx-context-menu-item-icon", this.IconCssClass)" />
}
@this.Text
@ChildContent
</a>
<a class="@CssClassHelper.Combine("dropdown-item", enabledEffective ? "" : "disabled")" role="@(enabledEffective ? "button" : "")" href="@Href" @onclick="HandleClick" @onclick:stopPropagation="@OnClickStopPropagation">
@if (this.Icon is not null)
{
<HxIcon Icon="this.Icon" CssClass="@CssClassHelper.Combine("hx-context-menu-item-icon", this.IconCssClass)" />
}
@this.Text
@ChildContent
</a>
</li>
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