Skip to content

Commit

Permalink
Add parameters to MBMenuSurface and MBAutocompletePagedField (#1277)
Browse files Browse the repository at this point in the history
* Add position parameter to MBAutoCompletePagedField

* Release notes

* Add notify opened parameter to MBMenuSurface

* Release notes
  • Loading branch information
simonziegler authored Mar 16, 2024
1 parent 826a9e3 commit 97d801b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

<div class="mdc-menu-surface--anchor">
<div @ref="@MenuReference"
class="mdc-menu mdc-menu-surface mdc-menu-surface--fixed"
class="mdc-menu-surface @ActiveConditionalClasses @(@class)"
style="@style"
@onfocusin="OnMenuFocusIn"
@onfocusout="OnMenuFocusOut"
tabindex="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public partial class MBAutocompletePagedField<TItem> : SingleSelectComponent<TIt
[Parameter] public MBTextAlignStyle? TextAlignStyle { get; set; }


/// <summary>
/// Menu surface positioning, defaults to <see cref="MBMenuSurfacePositioning.Fixed"/>.
/// </summary>
[Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Fixed;


/// <summary>
/// Field label.
/// </summary>
Expand Down Expand Up @@ -144,6 +150,9 @@ protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

_ = ConditionalCssClasses
.AddIf(MBMenuSurface.GetMenuSurfacePositioningClass(MenuSurfacePositioning), () => MenuSurfacePositioning != MBMenuSurfacePositioning.Regular);

AllowAllRenders();
}

Expand Down
24 changes: 18 additions & 6 deletions Material.Blazor/Components/MenuSurface/MBMenuSurface.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public partial class MBMenuSurface : ComponentFoundation
[Parameter] public MBMenuSurfacePositioning MenuSurfacePositioning { get; set; } = MBMenuSurfacePositioning.Regular;


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


/// <summary>
/// Called when the menu is closed.
/// </summary>
Expand Down Expand Up @@ -65,18 +71,24 @@ protected override void Dispose(bool disposing)
}


/// <summary>
/// For Material Theme to notify of menu closure via JS Interop.
/// </summary>
[JSInvokable()]
public void NotifyOpened()
{
OnMenuOpened?.Invoke();
}


/// <summary>
/// For Material Theme to notify of menu closure via JS Interop.
/// </summary>
[JSInvokable()]
public void NotifyClosed()
{
IsOpen = false;

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


Expand Down Expand Up @@ -114,7 +126,7 @@ internal override async Task InstantiateMcwComponent()
/// </summary>
/// <param name="surfacePositioning"></param>
/// <returns></returns>
private static string GetMenuSurfacePositioningClass(MBMenuSurfacePositioning surfacePositioning) =>
internal static string GetMenuSurfacePositioningClass(MBMenuSurfacePositioning surfacePositioning) =>
surfacePositioning switch
{
MBMenuSurfacePositioning.FullWidth => "mdc-menu-surface--fullwidth",
Expand Down
6 changes: 6 additions & 0 deletions Material.Blazor/Components/MenuSurface/MBMenuSurface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export function init(elem, dotNetObject) {
}
elem._menu = MDCMenuSurface.attachTo(elem);

const openedCallback = () => {
dotNetObject.invokeMethodAsync('NotifyOpened');
};

elem._menu.listen('MDCMenuSurface:opened', openedCallback);

const closedCallback = () => {
dotNetObject.invokeMethodAsync('NotifyClosed');
};
Expand Down
2 changes: 1 addition & 1 deletion Material.Blazor/Components/Slider/MBSlider.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public partial class MBSlider : InputComponent<decimal>


/// <summary>
/// For continuous input sets the debounce/throttle delay.
/// For continuous input sets the debounce/throttle delay in milliseconds.
/// </summary>
[Parameter] public uint ContinuousInputDelay { get; set; } = 300;

Expand Down
4 changes: 4 additions & 0 deletions Material.Blazor/wwwroot/material.blazor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13755,6 +13755,10 @@ function MBMenuSurface_init(elem, dotNetObject) {
return;
}
elem._menu = MDCMenuSurface.attachTo(elem);
var openedCallback = function openedCallback() {
dotNetObject.invokeMethodAsync('NotifyOpened');
};
elem._menu.listen('MDCMenuSurface:opened', openedCallback);
var closedCallback = function closedCallback() {
dotNetObject.invokeMethodAsync('NotifyClosed');
};
Expand Down
2 changes: 1 addition & 1 deletion Material.Blazor/wwwroot/material.blazor.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ title: ReleaseNotes
---
# Release Notes

#### [5.2.3](https://github.com/Material-Blazor/Material.Blazor/tree/5.2.3)

Released 2024-03-16

**Updates**
- Add `MenuSurfacePositioning` parameter to `MBAutocompletePagedField`.
- Add `OnMenuOpened` parameter to `MBMenuSurface`.

**New components**

**New features**

**Breaking Changes**

**Deprecated Components**

**Known issues**

<br />

#### [5.2.2](https://github.com/Material-Blazor/Material.Blazor/tree/5.2.2)

Released 2024-03-13
Expand Down

0 comments on commit 97d801b

Please sign in to comment.