Skip to content
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
3 changes: 2 additions & 1 deletion src/Core/Components/ProfileMenu/FluentProfileMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits FluentComponentBase

<div id="@Id" class="@ClassValue" style="@StyleValue" top-corner="@TopCorner"
@onclick="@(e => Open = !Open)">
@onclick="@ProfileMenuClickedAsync">
@StartTemplate
<FluentPersona Id="@PersonaId"
Image="@Image"
Expand All @@ -20,6 +20,7 @@
Style="@PopoverStyle"
HorizontalPosition="@HorizontalPosition.Start"
@bind-Open="@Open"
@bind-Open:after="@OpenChangedHandlerAsync"
@attributes="@AdditionalAttributes">
<Header>
@if (HeaderTemplate is null && (!string.IsNullOrEmpty(HeaderLabel) || !string.IsNullOrEmpty(HeaderButton)))
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Components/ProfileMenu/FluentProfileMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public FluentProfileMenu()
[Parameter]
public bool Open { get; set; } = false;

/// <summary>
/// Gets or sets the callback that is invoked when the open state changes.
/// </summary>
[Parameter]
public EventCallback<bool> OpenChanged { get; set; }

/// <summary>
/// Gets or sets whether popover should be forced to top right or top left (RTL).
/// </summary>
Expand Down Expand Up @@ -165,4 +171,19 @@ public FluentProfileMenu()

/// <summary />
private string PersonaId => $"{Id}-persona";

private async Task ProfileMenuClickedAsync()
{
Open = !Open;
await OpenChangedHandlerAsync();
}

/// <summary />
private async Task OpenChangedHandlerAsync()
{
if (OpenChanged.HasDelegate)
{
await OpenChanged.InvokeAsync(Open);
}
}
}
9 changes: 8 additions & 1 deletion tests/Core/ProfileMenu/FluentProfileMenuTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@
[Fact]
public void FluentProfileMenu_Default()
{
bool opened = false;

// Arrange && Act
var cut = Render(
@<FluentProfileMenu Image="@SamplePicture"
ButtonSize="20px"
ImageSize="48px"
@bind-Open="@opened"
Status="@PresenceStatus.Available"
StatusTitle="I'm available"
HeaderLabel="Microsoft"
FooterLabel="v 3.14"
Initials="BG"
FullName="Bill Gates"
EMail="[email protected]" />);
EMail="[email protected]" />
);

Assert.False(opened);

// Open the Popover
var button = cut.Find(".initials");
button.Click();

// Assert
Assert.True(opened);
cut.Verify();
}

Expand Down
Loading