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
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,11 @@
The text usually displayed in a 'tooltip' popup when the mouse is over the button.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentButton.StopPropagation">
<summary>
Gets or sets a way to prevent further propagation of the current event in the capturing and bubbling phases.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentButton.ChildContent">
<summary>
Gets or sets the content to be rendered inside the component.
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/Button/FluentButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ else
title=@Title
appearance=@Appearance.ToAttributeValue()
@onclick="@OnClickHandlerAsync"
@onclick:stopPropagation="@StopPropagation"
@attributes="AdditionalAttributes">
@if (IconStart != null)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Components/Button/FluentButton.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public partial class FluentButton : FluentComponentBase, IAsyncDisposable
[Parameter]
public string? Title { get; set; }

/// <summary>
/// Gets or sets a way to prevent further propagation of the current event in the capturing and bubbling phases.
/// </summary>
[Parameter]
public bool StopPropagation { get; set; } = false;

/// <summary>
/// Gets or sets the content to be rendered inside the component.
/// </summary>
Expand Down
43 changes: 43 additions & 0 deletions tests/Core/Button/FluentButtonTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,47 @@
// Assert
Assert.True(clicked);
}

[Fact]
public void FluentButton_StopPropagationFalse()
{
bool clickedondiv = false;
bool clicked = false;

// Arrange
// Not adding StopPropagation here explicitly because it is false by default
var cut = Render(@<div @onclick="@(e => {clickedondiv = true; })">
<FluentButton OnClick="@(e => { clicked = true; } )">
My button
</FluentButton>
</div>);

// Act
cut.Find("fluent-button").Click();

// Assert
Assert.True(clickedondiv);
Assert.True(clicked);
}

[Fact]
public void FluentButton_StopPropagationTrue()
{
bool clickedondiv = false;
bool clicked = false;

// Arrange
var cut = Render(@<div @onclick="@(e => {clickedondiv = true; })">
<FluentButton StopPropagation="true" OnClick="@(e => { clicked = true; } )">
My button
</FluentButton>
</div>);

// Act
cut.Find("fluent-button").Click();

// Assert
Assert.False(clickedondiv);
Assert.True(clicked);
}
}