Skip to content

Commit

Permalink
Fix Paginator menu not opening (#584)
Browse files Browse the repository at this point in the history
* Paginator, Menu and MenuSurface updates

* Update release notes

* Remove debugging text

* Clarify Action names
  • Loading branch information
simonziegler authored Dec 4, 2021
1 parent 8cbe541 commit 2007a19
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
12 changes: 12 additions & 0 deletions Material.Blazor/Components/Menu/MBMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Threading.Tasks;

namespace Material.Blazor
Expand All @@ -23,6 +24,12 @@ public partial class MBMenu : ComponentFoundation
[Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Regular;


/// <summary>
/// Called when the menu is closed.
/// </summary>
[Parameter] public Action OnMenuClosed { get; set; }


private DotNetObjectReference<MBMenu> ObjectReference { get; set; }
private ElementReference ElementReference { get; set; }
private bool IsOpen { get; set; } = false;
Expand Down Expand Up @@ -66,6 +73,11 @@ protected override void Dispose(bool disposing)
public void NotifyClosed()
{
IsOpen = false;

if (OnMenuClosed != null)
{
_ = InvokeAsync(OnMenuClosed);
}
}


Expand Down
12 changes: 12 additions & 0 deletions Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Material.Blazor.Internal;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Threading.Tasks;

namespace Material.Blazor
Expand All @@ -23,6 +24,12 @@ public partial class MBMenuSurface : ComponentFoundation
[Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Regular;


/// <summary>
/// Called when the menu is closed.
/// </summary>
[Parameter] public Action OnMenuClosed { get; set; }


private DotNetObjectReference<MBMenuSurface> ObjectReference { get; set; }
private ElementReference ElementReference { get; set; }
private bool IsOpen { get; set; } = false;
Expand Down Expand Up @@ -66,6 +73,11 @@ protected override void Dispose(bool disposing)
public void NotifyClosed()
{
IsOpen = false;

if (OnMenuClosed != null)
{
_ = InvokeAsync(OnMenuClosed);
}
}


Expand Down
4 changes: 2 additions & 2 deletions Material.Blazor/Components/Paginator/MBPaginator.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<MBIconButtonToggle @bind-Value="@ToggleOn"
IconOff="arrow_drop_down"
IconOn="arrow_drop_up"
@onclick="@OnMenuToggleAsync"
@ref="@IconButtonToggle" />
<div class="mdc-menu-surface--anchor">
<MBMenu @ref="Menu">
<MBMenu OnMenuClosed="@OnMenuClosed"
@ref="Menu">
@foreach (var itemsPerPage in ItemsPerPageSelection)
{
<MBListItem @key="@itemsPerPage"
Expand Down
39 changes: 27 additions & 12 deletions Material.Blazor/Components/Paginator/MBPaginator.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,33 @@ private int BackingPageNumber
private string PositionText => 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 <inheritdoc/> however DocFX cannot resolve to references outside Material.Blazor
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

ConditionalCssClasses
_ = ConditionalCssClasses
.AddIf("no-border", () => !RequiresBorder);

if (ItemsPerPage == 0)
Expand Down Expand Up @@ -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);
}


Expand Down
11 changes: 8 additions & 3 deletions articles/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ Released 2021-??-??

<br />

#### [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

<br />

#### [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**

Expand Down

0 comments on commit 2007a19

Please sign in to comment.