Skip to content

Commit 95939fb

Browse files
committed
Implement TitleTypo in DialogParameters. Fix #4126
Related Work Items: #412, #4126
1 parent 9f9b2da commit 95939fb

File tree

8 files changed

+63
-5
lines changed

8 files changed

+63
-5
lines changed

examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,12 @@
37693769
Gets or sets the title of the dialog.
37703770
</summary>
37713771
</member>
3772+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.DialogParameters.TitleTypo">
3773+
<summary>
3774+
Gets or sets the <see cref="T:Microsoft.FluentUI.AspNetCore.Components.Typography"/> style for the title text.
3775+
Defaults to <see cref="F:Microsoft.FluentUI.AspNetCore.Components.Typography.PaneHeader"/>.
3776+
</summary>
3777+
</member>
37723778
<member name="P:Microsoft.FluentUI.AspNetCore.Components.DialogParameters.Modal">
37733779
<summary>
37743780
Determines if the dialog is modal. Defaults to true.

examples/Demo/Shared/Pages/Dialog/Examples/DialogServiceExample.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
DialogParameters parameters = new()
4242
{
4343
Title = $"Hello {simplePerson.Firstname}",
44+
TitleTypo = Typography.H2,
4445
PrimaryAction = "Yes",
4546
PrimaryActionEnabled = false,
4647
SecondaryAction = "No",
4748
Width = "500px",
4849
TrapFocus = _trapFocus,
4950
Modal = _modal,
50-
PreventScroll = true
51+
PreventScroll = true
5152
};
5253

5354
IDialogReference dialog = await DialogService.ShowDialogAsync<SimpleDialog>(simplePerson, parameters);
5455
DialogResult? result = await dialog.Result;
5556

56-
5757
if (result.Data is not null)
5858
{
5959
SimplePerson? simplePerson = result.Data as SimplePerson;
@@ -64,4 +64,4 @@
6464
DemoLogger.WriteLine($"Dialog closed - Canceled: {result.Cancelled}");
6565
}
6666
}
67-
}
67+
}

src/Core/Components/Dialog/FluentDialogHeader.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div style="width: 100%;" tabindex="@TabIndex">
1212
@if (@ChildContent == null && Dialog.Instance?.Parameters?.ShowTitle == true)
1313
{
14-
<FluentLabel Typo="Typography.PaneHeader">@Dialog.Instance?.Parameters?.Title</FluentLabel>
14+
<FluentLabel Typo="@(Dialog.Instance?.Parameters?.TitleTypo ?? Typography.PaneHeader)">@Dialog.Instance?.Parameters?.Title</FluentLabel>
1515
}
1616
else
1717
{

src/Core/Components/Dialog/FluentDialogProvider.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private async Task<IDialogReference> ShowDialogAsync(IDialogReference dialogRefe
9191
dialogReference.Instance = dialog;
9292

9393
_internalDialogContext.References.Add(dialogReference);
94-
InvokeAsync(StateHasChanged);
94+
await InvokeAsync(StateHasChanged);
9595

9696
return dialogReference;
9797
});

src/Core/Components/Dialog/Parameters/DialogParameters.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public virtual HorizontalAlignment Alignment
3939
/// </summary>
4040
public string? Title { get; set; }
4141

42+
/// <summary>
43+
/// Gets or sets the <see cref="Typography"/> style for the title text.
44+
/// Defaults to <see cref="Typography.PaneHeader"/>.
45+
/// </summary>
46+
public Typography TitleTypo { get; set; } = Typography.PaneHeader;
47+
4248
/// <summary>
4349
/// Determines if the dialog is modal. Defaults to true.
4450
/// Obscures the area around the dialog.

src/Core/Components/Dialog/Parameters/IDialogParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface IDialogParameters
1111
string Id { get; set; }
1212
HorizontalAlignment Alignment { get; set; }
1313
string? Title { get; set; }
14+
Typography TitleTypo { get; set; }
1415
bool? Modal { get; set; }
1516
bool? TrapFocus { get; set; }
1617
bool ShowTitle { get; set; }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
<fluent-dialog id="xxx" class="fluent-dialog-main prevent-scroll" style="position: absolute; z-index: 999; top: 50%; left: 50%; --dialog-width: 500px; --dialog-height: 200px;" modal="true" trap-focus="true" blazor:ondialogdismiss="1" b-dsxskpj5rr="" blazor:elementreference="">
3+
<div class="stack-horizontal fluent-dialog-header" style="justify-content: start; align-items: start; column-gap: 10px; row-gap: 10px; width: 100%;" b-0nr62qx0mz="">
4+
<div style="width: 100%;" tabindex="0">
5+
<h4 typo="pane-header" class="fluent-typography" b-1nnnfjehkp="">Sample title as H2</h4>
6+
</div>
7+
<fluent-button type="button" id="xxx" appearance="stealth" blazor:onclick="8" aria-label="Close" b-x1200685t0="" blazor:elementreference="xxx">
8+
<svg style="width: 20px; fill: var(--neutral-foreground-rest);" focusable="false" viewBox="0 0 20 20" aria-hidden="true" blazor:onkeydown="11" blazor:onclick="12">
9+
<path d="m4.09 4.22.06-.07a.5.5 0 0 1 .63-.06l.07.06L10 9.29l5.15-5.14a.5.5 0 0 1 .63-.06l.07.06c.18.17.2.44.06.63l-.06.07L10.71 10l5.14 5.15c.18.17.2.44.06.63l-.06.07a.5.5 0 0 1-.63.06l-.07-.06L10 10.71l-5.15 5.14a.5.5 0 0 1-.63.06l-.07-.06a.5.5 0 0 1-.06-.63l.06-.07L9.29 10 4.15 4.85a.5.5 0 0 1-.06-.63l.06-.07-.06.07Z"></path>
10+
</svg>
11+
</fluent-button>
12+
<fluent-tooltip anchor="xxx" delay="300" aria-label="Tooltip" position="bottom" role="tooltip" blazor:ontooltipdismiss="9" blazor:elementreference="xxx">
13+
<div style="max-width: 500px; text-wrap: wrap;">Close</div>
14+
</fluent-tooltip>
15+
</div>
16+
<div class="stack-horizontal fluent-dialog-footer" style="justify-content: end; align-items: end; column-gap: 10px; row-gap: 10px; width: 100%;" b-0nr62qx0mz="">
17+
<fluent-button type="button" appearance="accent" blazor:onclick="10" b-x1200685t0="" blazor:elementreference="xxx">Close</fluent-button>
18+
</div>
19+
<div class="fluent-dialog-body">
20+
My body
21+
</div>
22+
</fluent-dialog>

tests/Core/Dialog/FluentDialogServiceTests.razor

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@
3636
cut.Verify();
3737
}
3838

39+
[Fact]
40+
public async Task FluentDialogService_ChangeHeaderTypo()
41+
{
42+
Services.AddFluentUIComponents();
43+
44+
// Arrange
45+
var cut = Render(@<FluentDialogProvider />);
46+
var dialogService = Services.GetRequiredService<IDialogService>();
47+
48+
// Act
49+
var dialog = await dialogService.ShowDialogAsync<TestDialogHeaderFooter>(new DialogParameters()
50+
{
51+
Height = "200px",
52+
Title = "Sample title as H2",
53+
TitleTypo = Typography.H2,
54+
PreventDismissOnOverlayClick = true,
55+
PreventScroll = true,
56+
});
57+
58+
// Assert
59+
cut.Verify();
60+
}
61+
3962
[Fact]
4063
public async Task FluentDialogService_HeightUnset()
4164
{

0 commit comments

Comments
 (0)