diff --git a/Material.Blazor/Components/Menu/MBMenu.razor.cs b/Material.Blazor/Components/Menu/MBMenu.razor.cs index 5860a27da..de964e3f5 100644 --- a/Material.Blazor/Components/Menu/MBMenu.razor.cs +++ b/Material.Blazor/Components/Menu/MBMenu.razor.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using System; using System.Threading.Tasks; namespace Material.Blazor @@ -23,6 +24,12 @@ public partial class MBMenu : ComponentFoundation [Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Regular; + /// + /// Called when the menu is closed. + /// + [Parameter] public Action OnMenuClosed { get; set; } + + private DotNetObjectReference ObjectReference { get; set; } private ElementReference ElementReference { get; set; } private bool IsOpen { get; set; } = false; @@ -66,6 +73,11 @@ protected override void Dispose(bool disposing) public void NotifyClosed() { IsOpen = false; + + if (OnMenuClosed != null) + { + _ = InvokeAsync(OnMenuClosed); + } } diff --git a/Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs b/Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs index a8991b9e4..c7e95589d 100644 --- a/Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs +++ b/Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs @@ -1,6 +1,7 @@ using Material.Blazor.Internal; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using System; using System.Threading.Tasks; namespace Material.Blazor @@ -23,6 +24,12 @@ public partial class MBMenuSurface : ComponentFoundation [Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Regular; + /// + /// Called when the menu is closed. + /// + [Parameter] public Action OnMenuClosed { get; set; } + + private DotNetObjectReference ObjectReference { get; set; } private ElementReference ElementReference { get; set; } private bool IsOpen { get; set; } = false; @@ -66,6 +73,11 @@ protected override void Dispose(bool disposing) public void NotifyClosed() { IsOpen = false; + + if (OnMenuClosed != null) + { + _ = InvokeAsync(OnMenuClosed); + } } diff --git a/Material.Blazor/Components/Paginator/MBPaginator.razor b/Material.Blazor/Components/Paginator/MBPaginator.razor index aca776cea..5a9930079 100644 --- a/Material.Blazor/Components/Paginator/MBPaginator.razor +++ b/Material.Blazor/Components/Paginator/MBPaginator.razor @@ -22,10 +22,10 @@
- + @foreach (var itemsPerPage in ItemsPerPageSelection) { PositionTextString(PageNumber); private bool PreviousDisabled => PageNumber <= 0; private string PositionTextString(int pageNumber) => $"{pageNumber * ItemsPerPage + 1:G0}-{Math.Min(ItemCount, (pageNumber + 1) * ItemsPerPage):G0} of {ItemCount:G0}"; - private bool ToggleOn { get; set; } + + + private bool toggleOn; + private bool ToggleOn + { + get => toggleOn; + set + { + if (value != toggleOn) + { + toggleOn = value; + + if (toggleOn) + { + _ = InvokeAsync(async () => await Menu.ToggleAsync()); + } + } + } + } // Would like to use however DocFX cannot resolve to references outside Material.Blazor @@ -126,7 +144,7 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - ConditionalCssClasses + _ = ConditionalCssClasses .AddIf("no-border", () => !RequiresBorder); if (ItemsPerPage == 0) @@ -157,21 +175,18 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } - private async Task OnMenuToggleAsync() + private void OnMenuItemClick(int itemsPerPage) { - if (ToggleOn) - { - await Menu.ToggleAsync(); - ToggleOn = false; - } + double ratio = (double)ItemsPerPage / itemsPerPage; + BackingItemsPerPage = itemsPerPage; + BackingPageNumber = Convert.ToInt32(PageNumber * ratio); } - private void OnMenuItemClick(int itemsPerPage) + private void OnMenuClosed() { - double ratio = (double)ItemsPerPage / (double)itemsPerPage; - BackingItemsPerPage = itemsPerPage; - BackingPageNumber = Convert.ToInt32(PageNumber * ratio); + toggleOn = false; + _ = InvokeAsync(StateHasChanged); } diff --git a/articles/ReleaseNotes.md b/articles/ReleaseNotes.md index fd225adcd..d768d0e66 100644 --- a/articles/ReleaseNotes.md +++ b/articles/ReleaseNotes.md @@ -22,14 +22,19 @@ Released 2021-??-??
-#### [2.0.0](https://github.com/Material-Blazor/Material.Blazor) -In Pre-Release Q4 2020 to Q4 2021 +#### [2.0.1](https://github.com/Material-Blazor/Material.Blazor) +Released 2021-12-04 + +- Fixes bug in MBPaginator where menu for number of items per pages doesn't open +
+ +#### [2.0.0](https://github.com/Material-Blazor/Material.Blazor) Released 2021-11-10 **Updates** -Material.Blazor is now built against .Net 6.0.0 GA +- Material.Blazor is now built against .Net 6.0.0 GA **New components**