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

[MenuProvider] Check whether the FluentMenuProvider is included #2793

Merged
merged 2 commits into from
Oct 11, 2024
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 @@ -6319,6 +6319,9 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentMenuItem.OnClickHandlerAsync(Microsoft.AspNetCore.Components.Web.MouseEventArgs)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentMenuProvider.#ctor">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuProvider.ClassValue">
<summary />
</member>
Expand All @@ -6344,6 +6347,11 @@
Action to be called when the menu is updated.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.IMenuService.ProviderId">
<summary>
Gets or sets the FluentMenuProvider ID.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.IMenuService.Menus">
<summary>
Gets the list of menus.
Expand Down Expand Up @@ -6383,6 +6391,11 @@
<see cref="P:Microsoft.FluentUI.AspNetCore.Components.IMenuService.Menus" />
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.MenuService.ProviderId">
<summary>
<see cref="P:Microsoft.FluentUI.AspNetCore.Components.IMenuService.ProviderId" />
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.MenuService.Add(Microsoft.FluentUI.AspNetCore.Components.FluentMenu)">
<summary>
<see cref="M:Microsoft.FluentUI.AspNetCore.Components.IMenuService.Add(Microsoft.FluentUI.AspNetCore.Components.FluentMenu)" />
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Components/Menu/FluentMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ protected override void OnInitialized()
_menuService = ServiceProvider?.GetService<IMenuService>();
if (MenuService != null && DrawMenuWithService)
{
if (string.IsNullOrEmpty(MenuService.ProviderId))
{
throw new ArgumentNullException(nameof(UseMenuService), "<FluentMenuProvider /> needs to be added to the main layout of your application/site.");
}

MenuService.Add(this);
}

Expand Down
7 changes: 7 additions & 0 deletions src/Core/Components/Menu/FluentMenuProvider.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public partial class FluentMenuProvider : FluentComponentBase
{
private IMenuService? _menuService = null;

/// <summary />
public FluentMenuProvider()
{
Id = Identifier.NewId();
}

/// <summary />
internal string? ClassValue => new CssBuilder(Class)
.AddClass("fluent-menu-provider")
Expand Down Expand Up @@ -42,6 +48,7 @@ protected override void OnInitialized()

if (MenuService != null)
{
MenuService.ProviderId = Id;
MenuService.OnMenuUpdated = () => InvokeAsync(StateHasChanged);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Components/Menu/Services/IMenuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public interface IMenuService : IDisposable
/// </summary>
Action OnMenuUpdated { get; set; }

/// <summary>
/// Gets or sets the FluentMenuProvider ID.
/// </summary>
public string? ProviderId { get; set; }

/// <summary>
/// Gets the list of menus.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Components/Menu/Services/MenuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public IEnumerable<FluentMenu> Menus
}
}

/// <summary>
/// <see cref="IMenuService.ProviderId" />
/// </summary>
public string? ProviderId { get; set; }

/// <summary>
/// <see cref="IMenuService.Add(FluentMenu)" />
/// </summary>
Expand Down
Loading