Skip to content

Commit 7a3bf3d

Browse files
committed
Fix a Combobox in a DialogBox
1 parent a5206ca commit 7a3bf3d

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

examples/Demo/FluentUI.Demo.Client/Documentation/Components/Dialog/FluentDialog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,22 @@ all parameters defined when calling `ShowDialogAsync`, as well as the `CloseAsyn
5454
Using `CloseAsync` you can pass a return object to the parent component.
5555
It is then retrieved in the `DialogResult` like in the example below.
5656

57-
```xml
57+
```razor
5858
@inherits FluentDialogInstance
5959
6060
<FluentDialogBody>
6161
Content dialog
6262
</FluentDialogBody>
63+
64+
@code
65+
{
66+
protected override Task OnActionClickedAsync(bool primary)
67+
{
68+
return primary
69+
? DialogInstance.CloseAsync()
70+
: DialogInstance.CancelAsync();
71+
}
72+
}
6373
```
6474

6575
> **Note:**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@page "/List/Combobox/Debug"
2+
@inject IDialogService DialogService
3+
4+
@* Combobox in a Dialog *@
5+
<FluentStack Margin="@Margin.All3"
6+
Padding="@Padding.All3"
7+
Style="@CommonStyles.NeutralBorder1"
8+
Orientation="Orientation.Vertical"
9+
Width="90%">
10+
<FluentButton OnClick="@OpenDialogAsync">Open</FluentButton>
11+
<div>
12+
Selected: @SelectedNumber
13+
</div>
14+
</FluentStack>
15+
16+
@code {
17+
int SelectedNumber = 0;
18+
19+
async Task OpenDialogAsync()
20+
{
21+
var result = await DialogService.ShowDrawerAsync<DebugComboboxDialog>(options =>
22+
{
23+
options.Modal = true;
24+
});
25+
26+
SelectedNumber = result.GetValue<int>();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@inherits FluentDialogInstance
2+
3+
<FluentDialogBody>
4+
<FluentCombobox Label="Number" Items="@Numbers" @bind-Value="@SelectedNumber" />
5+
6+
<div>
7+
Selected: @SelectedNumber
8+
</div>
9+
</FluentDialogBody>
10+
11+
@code
12+
{
13+
int[] Numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
14+
int SelectedNumber = 1;
15+
16+
protected override Task OnActionClickedAsync(bool primary)
17+
{
18+
return primary
19+
? DialogInstance.CloseAsync(SelectedNumber)
20+
: DialogInstance.CancelAsync();
21+
}
22+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ protected override Task OnAfterRenderAsync(bool firstRender)
9999
/// <summary />
100100
internal async Task OnToggleAsync(DialogToggleEventArgs args)
101101
{
102+
if (string.CompareOrdinal(args.Id, Instance?.Id) != 0)
103+
{
104+
return;
105+
}
106+
102107
// Raise the event received from the Web Component
103108
var dialogEventArgs = await RaiseOnStateChangeAsync(args);
104109

tests/Core/Components/Dialog/FluentDialogTests.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
// Act
9393
var dialogTask = DialogService.ShowDialogAsync<Templates.DialogRender>(options =>
9494
{
95+
options.Id = "my-id";
96+
9597
options.OnStateChange = (args) =>
9698
{
9799
dialogEventArgs = args;

0 commit comments

Comments
 (0)