Skip to content

Commit 3b79218

Browse files
committed
Fixes
1 parent d3035ec commit 3b79218

26 files changed

Lines changed: 144 additions & 156 deletions

src/CodeBeam.MudBlazor.Extensions/Base/MudBaseInputExtended.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ public abstract class MudBaseInputExtended<T> : MudBaseInput<T>
1818
/// </summary>
1919
protected MudBaseInputExtended()
2020
{
21-
Converter = new DefaultConverter<T>
22-
{
23-
Culture = GetCulture,
24-
Format = GetFormat
25-
};
26-
2721
//using var registerScope = CreateRegisterScope();
2822
//_textState = registerScope.RegisterParameter<string?>(nameof(Text))
2923
// .WithParameter(() => Text)
@@ -41,8 +35,6 @@ protected MudBaseInputExtended()
4135
// .WithChangeHandler(UpdateInputIdStateAsync);
4236
}
4337

44-
45-
4638
/// <summary>
4739
/// Fires on input.
4840
/// </summary>
@@ -171,7 +163,5 @@ public async Task<bool> OnBeforeInputFromJs(BeforeInputJsDto dto)
171163
/// <param name="args">An object containing event data for the input operation.</param>
172164
/// <returns>A task that represents the asynchronous operation. The default implementation returns a completed task.</returns>
173165
protected virtual Task OnBeforeInputAsync(BeforeInputEventArgs args) => Task.CompletedTask;
174-
175-
176166
}
177167
}

src/CodeBeam.MudBlazor.Extensions/Components/ChipField/MudChipField.razor

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
OnClearButtonClick="@(async() => await OnClearButtonClick.InvokeAsync())"
1313
OnDebounceIntervalElapsed="@(async() => await OnDebounceIntervalElapsed.InvokeAsync())"
1414
OnInternalInputChanged="@(async() => await OnInternalInputChanged.InvokeAsync())"
15-
ShrinkLabel="@(Values?.Any() ?? false)"
15+
ShrinkLabel="@(_valuesState.Value?.Any() ?? false)"
1616
Clearable="@Clearable"
1717
AutoFocus="@AutoFocus"
1818
Class="@Class"
@@ -43,19 +43,19 @@
4343
Variant="@Variant"
4444
@bind-Value="@_internalValue"
4545
TextChanged="@(async() => await TextChanged.InvokeAsync())"
46-
ShowVisualiser="@(Values?.Any() ?? false)">
46+
ShowVisualiser="@(_valuesState.Value?.Any() ?? false)">
4747

4848
<DataVisualiser>
4949
<MudChipSet T="T" Class="@ChipClassname" Style="@ChipStylename" AllClosable="@Closeable" OnClose="Closed">
50-
@for (int i = 0; i < (MaxChips == 0 ? Values?.Count ?? 0 : (MaxChips < (Values?.Count ?? 0) ? MaxChips : Values?.Count ?? 0)); i++)
50+
@for (int i = 0; i < (MaxChips == 0 ? _valuesState.Value?.Count ?? 0 : (MaxChips < (_valuesState.Value?.Count ?? 0) ? MaxChips : _valuesState.Value?.Count ?? 0)); i++)
5151
{
5252
int a = i;
53-
<MudChip T="T" Class="@ClassChip" Style="@StyleChip" Ripple="false" Text="@(Values != null ? Values[a] : string.Empty)" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
53+
<MudChip T="T" Class="@ClassChip" Style="@StyleChip" Ripple="false" Text="@(_valuesState.Value != null ? _valuesState.Value[a] : string.Empty)" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
5454
}
5555
</MudChipSet>
56-
@if (Values != null && MaxChips != 0 && MaxChips < Values.Count)
56+
@if (_valuesState.Value != null && MaxChips != 0 && MaxChips < _valuesState.Value.Count)
5757
{
58-
<MudChip T="T" Ripple="false" Text="@($"+{Values.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
58+
<MudChip T="T" Ripple="false" Text="@($"+{_valuesState.Value.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
5959
}
6060
</DataVisualiser>
6161

src/CodeBeam.MudBlazor.Extensions/Components/ChipField/MudChipField.razor.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public MudChipField()
4848
/// <summary>
4949
/// /The list of values.
5050
/// </summary>
51-
[Parameter]
51+
[Parameter, ParameterState]
5252
public List<string>? Values { get; set; }
5353

5454
/// <summary>
@@ -134,7 +134,7 @@ public MudChipField()
134134
/// </summary>
135135
/// <param name="args"></param>
136136
/// <returns></returns>
137-
protected internal async Task HandleKeyDown(KeyboardEventArgs args)
137+
protected internal Task HandleKeyDown(KeyboardEventArgs args)
138138
{
139139
//var result = args.Key;
140140
//if (result.Equals(Delimiter, StringComparison.InvariantCultureIgnoreCase) && _internalValue != null)
@@ -158,17 +158,17 @@ protected internal async Task HandleKeyDown(KeyboardEventArgs args)
158158
//}
159159
//await Task.Delay(10);
160160
//await SetValueAsync(_internalValue);
161-
await OnKeyDown.InvokeAsync(args);
161+
return OnKeyDown.InvokeAsync(args);
162162
}
163163

164164
/// <summary>
165165
/// Protected keyup event.
166166
/// </summary>
167167
/// <param name="args"></param>
168168
/// <returns></returns>
169-
protected async Task HandleKeyUp(KeyboardEventArgs args)
169+
protected Task HandleKeyUp(KeyboardEventArgs args)
170170
{
171-
await OnKeyUp.InvokeAsync(args);
171+
return OnKeyUp.InvokeAsync(args);
172172
}
173173

174174
/// <summary>
@@ -186,7 +186,7 @@ protected internal async Task HandleBeforeInput(BeforeInputEventArgs args)
186186
if (args.IsInsert && args.Data == Delimiter && _internalValue is not null)
187187
{
188188
args.PreventDefault = true;
189-
var currentText = base.ConvertSet(_internalValue);
189+
var currentText = ConvertSet(_internalValue);
190190

191191
if (!string.IsNullOrEmpty(currentText))
192192
{
@@ -200,7 +200,7 @@ protected internal async Task HandleBeforeInput(BeforeInputEventArgs args)
200200
return;
201201
}
202202

203-
if (args.IsDeleteBackward && string.IsNullOrEmpty(base.ConvertSet(_internalValue)) && _valuesState.Value is { Count: > 0 } && BackspaceChipRemoval)
203+
if (args.IsDeleteBackward && string.IsNullOrEmpty(ConvertSet(_internalValue)) && _valuesState.Value is { Count: > 0 } && BackspaceChipRemoval)
204204
{
205205
args.PreventDefault = true;
206206

@@ -247,7 +247,7 @@ protected async Task SetChips()
247247
{
248248
await _valuesState.SetValueAsync(new List<string>());
249249
}
250-
_valuesState.Value.Add(base.ConvertSet(_internalValue) ?? "");
250+
_valuesState.Value.Add(ConvertSet(_internalValue) ?? "");
251251
await ValuesChanged.InvokeAsync(_valuesState.Value);
252252
if (RuntimeLocation.IsServerSide)
253253
{
@@ -290,6 +290,5 @@ public async Task ClearTextField()
290290
{
291291
await _textFieldExtendedReference.Clear();
292292
}
293-
294293
}
295294
}

src/CodeBeam.MudBlazor.Extensions/Components/CodeInput/MudCodeInput.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<MudInputControl Class="@Class" Style="@Style" Error="@ErrorState.Value" ErrorText="@GetErrorText()" Required="false">
66
<InputContent>
77
<div class="@Classname" style="@InnerStyle">
8-
@for (int i = 0; i < Count; i++)
8+
@for (int i = 0; i < _count.Value; i++)
99
{
1010
int a = i;
1111
<MudTextFieldExtended @ref="_elementReferences[a]" T="T" Class="@InputClassname" Style="@(Margin == Margin.Dense ? "width: 32px" : "width: 42px")" MaxLength="1"

src/CodeBeam.MudBlazor.Extensions/Components/CodeInput/MudCodeInput.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private async Task OnCountChanged()
100100
/// <summary>
101101
/// The value of the input.
102102
/// </summary>
103-
[Parameter]
103+
[Parameter, ParameterState]
104104
[Category(CategoryTypes.FormComponent.Behavior)]
105105
public T? Value { get; set; }
106106

@@ -114,7 +114,7 @@ private async Task OnCountChanged()
114114
/// <summary>
115115
/// The number of text fields.
116116
/// </summary>
117-
[Parameter]
117+
[Parameter, ParameterState]
118118
[Category(CategoryTypes.FormComponent.Behavior)]
119119
public int Count { get; set; }
120120

@@ -218,7 +218,7 @@ protected async Task CheckFocus(int count)
218218
_skipRefocus = false;
219219
return;
220220
}
221-
string str = base.ConvertSet(_theValue.Value) ?? string.Empty;
221+
string str = ConvertSet(_theValue.Value) ?? string.Empty;
222222
await _elementReferences[str.Length].FocusAsync();
223223
}
224224

@@ -298,7 +298,7 @@ public async Task SetValue()
298298
/// <returns></returns>
299299
public async Task SetValueFromOutside(T? value)
300300
{
301-
string? val = base.ConvertSet(value);
301+
string? val = ConvertSet(value);
302302
if (_count.Value < val?.Length)
303303
{
304304
val = val.Substring(0, _count.Value);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{
5656
foreach (var item in CollectionsMarshal.AsSpan(collection))
5757
{
58-
<MudChip Class="@ChipClass" Value="@item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? base.ConvertSet(item.Value) : item.Text)"
58+
<MudChip Class="@ChipClass" Value="@item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? ConvertSet(item.Value) : item.Text)"
5959
Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation />
6060
}
6161
}

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public MudComboBox()
3434
/// <param name="value"></param>
3535
protected internal void SetSearchString(T value)
3636
{
37-
_searchString = base.ConvertSet(value);
37+
_searchString = ConvertSet(value);
3838
}
3939

4040
internal string? _searchString { get; set; }
@@ -537,7 +537,7 @@ protected async Task SyncMultiselectionValues(bool singleToMultiselection)
537537
}
538538
else
539539
{
540-
if (ReadValue is string && string.IsNullOrWhiteSpace(base.ConvertSet(ReadValue)))
540+
if (ReadValue is string && string.IsNullOrWhiteSpace(ConvertSet(ReadValue)))
541541
{
542542
SelectedValues = new HashSet<T?>();
543543
}
@@ -552,7 +552,7 @@ protected async Task SyncMultiselectionValues(bool singleToMultiselection)
552552
else
553553
{
554554
await SetValueAndUpdateTextAsync(SelectedValues.LastOrDefault(), false);
555-
_searchString = base.ConvertSet(SelectedValues.LastOrDefault());
555+
_searchString = ConvertSet(SelectedValues.LastOrDefault());
556556
}
557557
}
558558

@@ -655,13 +655,13 @@ protected Task UpdateDataVisualiserTextAsync()
655655
{
656656
if (!Strict && !Items.Select(x => x.Value).Contains(val))
657657
{
658-
textList.Add(ToStringFunc != null ? ToStringFunc(val) : base.ConvertSet(val));
658+
textList.Add(ConvertSet(val));
659659
continue;
660660
}
661661
var item = Items.FirstOrDefault(x => x != null && (x.Value == null ? val == null : Comparer != null ? Comparer.Equals(x.Value, val) : x.Value.Equals(val)));
662662
if (item != null)
663663
{
664-
textList.Add(!string.IsNullOrWhiteSpace(item.Text) ? item.Text : base.ConvertSet(item.Value));
664+
textList.Add(!string.IsNullOrWhiteSpace(item.Text) ? item.Text : ConvertSet(item.Value));
665665
}
666666
}
667667
}
@@ -691,8 +691,8 @@ protected Task UpdateDataVisualiserTextAsync()
691691
{
692692
var item = Items?.FirstOrDefault(x => ReadValue == null ? x.Value == null : Comparer != null ? Comparer.Equals(ReadValue, x.Value) : ReadValue.Equals(x.Value));
693693
_dataVisualiserText = item is null
694-
? base.ConvertSet(ReadValue)
695-
: (!string.IsNullOrWhiteSpace(item.Text) ? item.Text : base.ConvertSet(item.Value));
694+
? ConvertSet(ReadValue)
695+
: (!string.IsNullOrWhiteSpace(item.Text) ? item.Text : ConvertSet(item.Value));
696696

697697
return Task.CompletedTask;
698698
}
@@ -711,7 +711,7 @@ protected async Task UpdateComboBoxValueAsync(T? value, bool updateText = true,
711711
await SetValueAndUpdateTextAsync(value, updateText, force);
712712
if (updateSearchString)
713713
{
714-
_searchString = base.ConvertSet(ReadValue);
714+
_searchString = ConvertSet(ReadValue);
715715
await _inputReference.SetText(_searchString);
716716
}
717717
}
@@ -809,7 +809,7 @@ protected override async Task OnParametersSetAsync()
809809
await ForceUpdateItems();
810810
if (MultiSelection == false)
811811
{
812-
_searchString = base.ConvertSet(ReadValue);
812+
_searchString = ConvertSet(ReadValue);
813813
if (_inputReference != null)
814814
{
815815
await _inputReference?.SetText(_searchString);
@@ -1052,7 +1052,7 @@ protected internal async Task HandleOnBlur(FocusEventArgs obj)
10521052
if (Strict)
10531053
{
10541054
// Check if the user-provided search string is an exact (case-insensitive) match against an item in the collection.
1055-
var item = Items.FirstOrDefault(x => base.ConvertSet(x.Value)?.Equals(_searchString, StringComparison.OrdinalIgnoreCase) == true);
1055+
var item = Items.FirstOrDefault(x => ConvertSet(x.Value)?.Equals(_searchString, StringComparison.OrdinalIgnoreCase) == true);
10561056
if (item is not null)
10571057
await ToggleOption(item, true);
10581058

@@ -1550,7 +1550,7 @@ public async Task ActivateFirstItem(string? firstLetter = null)
15501550

15511551

15521552
// Get a collection of items that start with "firstLetter".
1553-
var items = Items.Where(x => base.ConvertSet(x.Value)?.StartsWith(firstLetter, StringComparison.OrdinalIgnoreCase) == true).ToList();
1553+
var items = Items.Where(x => ConvertSet(x.Value)?.StartsWith(firstLetter, StringComparison.OrdinalIgnoreCase) == true).ToList();
15541554
if (!items.Any())
15551555
{
15561556
if (_lastActivatedItem is not null)
@@ -1701,5 +1701,18 @@ protected bool HasEligibleItems()
17011701
///
17021702
/// </summary>
17031703
protected internal Color EffectiveCheckBoxUnCheckedColor => CheckBoxUnCheckedColor ?? Color;
1704+
1705+
/// <inheritdoc />
1706+
protected override string? ConvertSet(T? input) => ConverterSetCore(input);
1707+
1708+
internal string? ConverterSetCore(T? input)
1709+
{
1710+
if (ToStringFunc is null)
1711+
{
1712+
return base.ConvertSet(input);
1713+
}
1714+
1715+
return ToStringFunc(input);
1716+
}
17041717
}
17051718
}

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.AspNetCore.Components;
22
using MudBlazor;
3-
using MudBlazor.Extensions;
43
using MudBlazor.Utilities;
4+
using MudBlazor.Extensions;
55

66
namespace MudExtensions
77
{
@@ -43,7 +43,7 @@ public partial class MudComboBoxItem<T> : MudComponentBase, IDisposable
4343
/// The parent select component
4444
/// </summary>
4545
[CascadingParameter]
46-
MudComboBox<T> MudComboBox { get; set; } = null!;
46+
private MudComboBox<T>? MudComboBox { get; set; }
4747

4848
/// <summary>
4949
/// Prevents the user from interacting with this item.
@@ -150,17 +150,17 @@ protected string? DisplayString
150150
{
151151
get
152152
{
153-
var converter = MudComboBox?.Converter;
154-
if (MudComboBox?.ItemPresenter == ValuePresenter.None)
155-
{
156-
if (converter == null)
157-
return Value?.ToString();
158-
return converter.Convert(Value);
159-
}
160-
161-
if (converter == null)
162-
return $"{(string.IsNullOrWhiteSpace(Text) ? Value : Text)}";
163-
return !string.IsNullOrWhiteSpace(Text) ? Text : converter.Convert(Value);
153+
var hasText = !string.IsNullOrWhiteSpace(Text);
154+
155+
if (MudComboBox == null)
156+
return hasText ? Text : Value?.ToString();
157+
158+
if (MudComboBox.ItemPresenter == ValuePresenter.None)
159+
return MudComboBox.ConverterSetCore(Value);
160+
161+
return hasText
162+
? Text
163+
: MudComboBox.ConverterSetCore(Value);
164164
}
165165
}
166166

@@ -259,7 +259,7 @@ protected bool IsEligible()
259259
}
260260
else
261261
{
262-
if (MudComboBox?.Converter?.Convert(Value)?.Contains(MudComboBox._searchString ?? string.Empty, StringComparison.OrdinalIgnoreCase) == true)
262+
if (MudComboBox?.ConverterSetCore(Value)?.Contains(MudComboBox._searchString ?? string.Empty, StringComparison.OrdinalIgnoreCase) == true)
263263
return true;
264264
}
265265

@@ -277,7 +277,7 @@ protected void SyncSelected()
277277
if (MudComboBox.MultiSelection && MudComboBox?.SelectedValues?.Contains(Value) == true)
278278
Selected = true;
279279

280-
else if (MudComboBox?.MultiSelection == false && ((MudComboBox.Value is null && Value is null) || MudComboBox.Value?.Equals(Value) == true))
280+
else if (MudComboBox?.MultiSelection == false && ((MudComboBox.GetState(x => x.Value) is null && Value is null) || MudComboBox.GetState(x => x.Value)?.Equals(Value) == true))
281281
Selected = true;
282282
else
283283
Selected = false;
@@ -289,9 +289,13 @@ protected void SyncSelected()
289289
/// <returns></returns>
290290
protected async Task HandleOnClick()
291291
{
292-
await MudComboBox.ToggleOption(this, !Selected);
293-
await InvokeAsync(StateHasChanged);
294-
await MudComboBox.FocusAsync();
292+
if (MudComboBox is not null)
293+
{
294+
await MudComboBox.ToggleOption(this, !Selected);
295+
await InvokeAsync(StateHasChanged);
296+
await MudComboBox.FocusAsync();
297+
}
298+
295299
await OnClick.InvokeAsync();
296300
}
297301

0 commit comments

Comments
 (0)