Skip to content

Commit

Permalink
[Stack] Added 'Stretch' horizontal alignment option (#2800)
Browse files Browse the repository at this point in the history
* Added missing 'Stretch' horizontal alignment option to FluentStack

Introduced a new horizontal alignment option, `Stretch`, to the `FluentStack` component. Updated the `HorizontalAlignment` enum in `HorizontalAlignment.cs` to include the `Stretch` value with a summary comment. Modified the `GetHorizontalAlignment` method in `FluentStack.razor.cs` to map `HorizontalAlignment.Stretch`  to the string "stretch".

* Add validation to Alignment property in DialogParameters

The Alignment property now includes a custom setter that throws an ArgumentException if set to HorizontalAlignment.Stretch, ensuring this value is not supported.

* Moved "_alignment" variable declaration to top of DialogParameters class

* Added a note re. stretch to the XML documentation for the `Alignment` property

* Added unit test for DialogParameters invalid Aligment value

---------

Co-authored-by: Vincent Baaij <[email protected]>
Co-authored-by: Denis Voituron <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent 227e2b7 commit 1a408be
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Core/Components/Dialog/Parameters/DialogParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ namespace Microsoft.FluentUI.AspNetCore.Components;

public class DialogParameters : ComponentParameters, IDialogParameters
{
private HorizontalAlignment _alignment = HorizontalAlignment.Center;

public string Id { get; set; } = Identifier.NewId();

/// <summary>
/// Gets or sets the dialog position:
/// left (full height), right (full height)
/// or screen middle (using Width and Height properties).
/// </summary>
public virtual HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Center;

/// HorizontalAlignment.Stretch is not supported for this property.
/// </summary>
public virtual HorizontalAlignment Alignment
{
set
{
if (value == HorizontalAlignment.Stretch)
{
throw new ArgumentException("Alignment HorizontalAlignment.Stretch is not supported for DialogParameters");
}
_alignment = value;
}
get
{
return _alignment;
}
}

/// <summary>
/// Gets or sets the title of the dialog.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/Stack/FluentStack.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private string GetHorizontalAlignment()
HorizontalAlignment.Center => "center",
HorizontalAlignment.Right => "end",
HorizontalAlignment.End => "end",
HorizontalAlignment.Stretch => "stretch",
_ => "start",
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Enums/HorizontalAlignement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public enum HorizontalAlignment
/// The content is aligned to the end.
/// </summary>
End,

/// <summary>
/// The content is stretched to fill the available space.
/// </summary>
Stretch,
}
22 changes: 22 additions & 0 deletions tests/Core/Dialog/FluentDialogServiceTests.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Xunit;
@using HorizontalAlignment = Microsoft.FluentUI.AspNetCore.Components.HorizontalAlignment
@inherits TestContext
@code
{
Expand Down Expand Up @@ -115,6 +116,27 @@
Assert.Equal("Oh yes", cut.Find("fluent-button[appearance='accent']").InnerHtml);
}

[Fact]
public async Task FluentDialogService_AlignmentInvalid()
{
Services.AddFluentUIComponents();

// Arrange
var cut = Render(@<FluentDialogProvider/> );
var dialogService = Services.GetRequiredService<IDialogService>();

// Act/Assert
var exception = await Assert.ThrowsAsync<ArgumentException>(async () =>
{
var dialog = await dialogService.ShowDialogAsync<TestDialogHeaderFooter>(new DialogParameters()
{
Alignment = HorizontalAlignment.Stretch, // Stretch is not supported
});
});

Assert.Equal("Alignment HorizontalAlignment.Stretch is not supported for DialogParameters", exception.Message);
}

private class UpdateDialogUser
{
public int Id { get; set; } = 0;
Expand Down

0 comments on commit 1a408be

Please sign in to comment.