Skip to content

Commit d5d41f0

Browse files
authored
MudSelectExtended & MudCombobox: Add Modal (#590)
1 parent a4d7956 commit d5d41f0

File tree

6 files changed

+54
-17
lines changed

6 files changed

+54
-17
lines changed

docs/CodeBeam.MudBlazor.Extensions.Docs/Pages/Components/ComboBox/Examples/ComboBoxExample7.razor

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<MudGrid>
44
<MudItem xs="12" sm="8" Class="d-flex gap-4 align-center justify-center">
5-
<MudComboBox @bind-Value="@_value" @bind-Text="@_text" @bind-SelectedValues="@_selectedValues" Variant="Variant.Filled" Label="Highlighted" Editable="true" MultiSelection="@_multiselection"
5+
<MudComboBox @bind-Value="@_value" @bind-Text="@_text" @bind-SelectedValues="@_selectedValues" Variant="Variant.Filled" Label="Highlighted" Editable="true" MultiSelection="@_multiselection" Modal="@_modal"
66
autocomplete="new-password" Color="_color" Clearable="_clearable" Strict="_strict" Highlight="true" HighlightClass="@(_customHighlightClass ? "mud-theme-primary" : null)" EnableFilter="_enableFilter">
77
<MudComboBoxItem Value="@("Foo")">Foo</MudComboBoxItem>
88
<MudComboBoxItem Value="@("Bar")">Bar</MudComboBoxItem>
@@ -14,7 +14,7 @@
1414
}
1515
</MudComboBox>
1616

17-
<MudComboBox @bind-Value="@_value" @bind-Text="@_text" @bind-SelectedValues="@_selectedValues" Variant="Variant.Filled" Label="With NoItemsContent" Editable="true" MultiSelection="@_multiselection"
17+
<MudComboBox @bind-Value="@_value" @bind-Text="@_text" @bind-SelectedValues="@_selectedValues" Variant="Variant.Filled" Label="With NoItemsContent" Editable="true" MultiSelection="@_multiselection" Modal="@_modal"
1818
autocomplete="new-password" Color="_color" Clearable="_clearable" Strict="_strict" EnableFilter="_enableFilter">
1919
<ChildContent>
2020
<MudComboBoxItem Value="@("Foo")">Foo</MudComboBoxItem>
@@ -41,20 +41,22 @@
4141
<MudSwitchM3 @bind-Value="@_clearable" Label="Clearable" Color="Color.Secondary" />
4242
<MudSwitchM3 @bind-Value="@_customHighlightClass" Label="Custom Highlight" Color="Color.Secondary" />
4343
<MudSwitchM3 @bind-Value="@_enableFilter" Label="Enable Filter" Color="Color.Secondary" />
44+
<MudSwitchM3 @bind-Value="@_modal" Label="Modal" Color="Color.Secondary" />
4445
</MudStack>
4546
</MudItem>
4647
</MudGrid>
4748

4849
@code {
49-
string? _value;
50-
string? _text;
51-
IEnumerable<string>? _selectedValues;
52-
Color _color = Color.Primary;
53-
bool _multiselection;
54-
bool _clearable;
55-
bool _strict;
56-
bool _customHighlightClass;
57-
bool _enableFilter = true;
50+
private string? _value;
51+
private string? _text;
52+
private IEnumerable<string>? _selectedValues;
53+
private Color _color = Color.Primary;
54+
private bool _multiselection;
55+
private bool _clearable;
56+
private bool _strict;
57+
private bool _customHighlightClass;
58+
private bool _enableFilter = true;
59+
private bool _modal = true;
5860

5961
private string[] states =
6062
{

docs/CodeBeam.MudBlazor.Extensions.Docs/Pages/Components/SelectExtended/Examples/SelectExtendedExample1.razor

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
<MudGrid>
44
<MudItem xs="12" sm="8">
55
<MudStack>
6-
<MudSelectExtended T="string" Label="RenderFragment Based" Disabled="_disabled">
6+
<MudSelectExtended T="string" Label="RenderFragment Based" Disabled="_disabled" Modal="@_modal">
77
<MudSelectItemExtended Value="@("Foo")" Text="Foo" />
88
<MudSelectItemExtended Value="@("Bar")" Text="Bar" />
99
<MudSelectItemExtended Value="@("Fizz")" Text="Fizz" />
1010
<MudSelectItemExtended Value="@("Buzz")" Text="Buzz" />
1111
</MudSelectExtended>
12-
<MudSelectExtended T="string" Label="Data Based" ItemCollection="_collection" Disabled="_disabled" />
13-
<MudSelectExtended T="string" Label="Data Based" ItemCollection="_collection" Disabled="_disabled" AddNullItem="true" AddedNullItemText="@_nullItemText" />
12+
<MudSelectExtended T="string" Label="Data Based" ItemCollection="_collection" Disabled="_disabled" Modal="@_modal" />
13+
<MudSelectExtended T="string" Label="Data Based" ItemCollection="_collection" Disabled="_disabled" Modal="@_modal" AddNullItem="true" AddedNullItemText="@_nullItemText" />
1414
</MudStack>
1515
</MudItem>
1616

1717
<MudItem xs="12" sm="4">
1818
<MudStack>
1919
<MudSwitchM3 @bind-Value="_disabled" Color="Color.Secondary" Label="Disabled" />
20+
<MudSwitchM3 @bind-Value="_modal" Color="Color.Secondary" Label="Modal" />
2021
<MudTextField @bind-Value="_nullItemText" Label="Null Item Text" Variant="Variant.Outlined" />
2122
</MudStack>
2223
</MudItem>
2324
</MudGrid>
2425

2526
@code {
2627
private bool _disabled = false;
28+
private bool _modal = true;
2729
private string[] _collection = new string[] { "Foo", "Bar", "Fizz", "Buzz" };
2830
private string? _nullItemText = "None";
2931
}

src/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@
174174

175175
</CascadingValue>
176176
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
177-
<MudOverlay Visible="@_isOpen" @onmousedown="@CloseMenu" LockScroll="@LockScroll" />
177+
<MudOverlay Visible="@_isOpen" @onmousedown="@CloseMenu" Modal="@GetModal()" AutoClose="@(!GetModal())" OnClosed="@(() => CloseMenu())" LockScroll="@LockScroll" />

src/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public partial class MudComboBox<T> : MudBaseInputExtended<T>
1515
{
1616
#region Constructor, Injected Services, Parameters, Fields
1717

18+
[Inject]
19+
private IPopoverService PopoverService { get; set; } = null!;
20+
1821
/// <summary>
1922
/// Constructor for ComboBox
2023
/// </summary>
@@ -325,6 +328,19 @@ protected internal void SetSearchString(T value)
325328
[Category(CategoryTypes.FormComponent.ListBehavior)]
326329
public bool SelectAll { get; set; }
327330

331+
/// <summary>
332+
/// If true prevent background interaction when open. Default is true.
333+
/// </summary>
334+
[Parameter]
335+
[Category(CategoryTypes.List.Selecting)]
336+
public bool? Modal { get; set; } = true;
337+
338+
/// <summary>
339+
///
340+
/// </summary>
341+
/// <returns></returns>
342+
protected bool GetModal() => Modal ?? PopoverService.PopoverOptions.ModalOverlay;
343+
328344
/// <summary>
329345
/// Sets position of the Select All checkbox
330346
/// </summary>

src/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@
182182
</CascadingValue>
183183

184184
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
185-
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu())" LockScroll="@LockScroll" />
185+
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu())" Modal="@GetModal()" AutoClose="@(!GetModal())" OnClosed="@(() => CloseMenu())" LockScroll="@LockScroll" />

src/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public MudSelectExtended()
2525
IconSize = Size.Medium;
2626
}
2727

28-
[Inject] private IKeyInterceptorService KeyInterceptorService { get; set; } = null!;
28+
[Inject]
29+
private IKeyInterceptorService KeyInterceptorService { get; set; } = null!;
30+
31+
[Inject]
32+
private IPopoverService PopoverService { get; set; } = null!;
2933

3034
private MudListExtended<T?>? _list;
3135
private bool _dense;
@@ -178,6 +182,19 @@ public MudSelectExtended()
178182
[Category(CategoryTypes.List.Selecting)]
179183
public bool NoWrap { get; set; }
180184

185+
/// <summary>
186+
/// If true prevent background interaction when open. Default is true.
187+
/// </summary>
188+
[Parameter]
189+
[Category(CategoryTypes.List.Selecting)]
190+
public bool? Modal { get; set; } = true;
191+
192+
/// <summary>
193+
///
194+
/// </summary>
195+
/// <returns></returns>
196+
protected bool GetModal() => Modal ?? PopoverService.PopoverOptions.ModalOverlay;
197+
181198
/// <summary>
182199
/// User class names for the popover, separated by space
183200
/// </summary>

0 commit comments

Comments
 (0)