Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/CodeBeam.MudBlazor.Extensions/Base/MudBaseInputExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ public abstract class MudBaseInputExtended<T> : MudBaseInput<T>
/// </summary>
protected MudBaseInputExtended()
{
Converter = new DefaultConverter<T>
Copy link
Copy Markdown
Contributor Author

@ScarletKuro ScarletKuro Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, MudBaseInput already sets a GetDefaultConverter() => DefaultConverter<T>

{
Culture = GetCulture,
Format = GetFormat
};

//using var registerScope = CreateRegisterScope();
//_textState = registerScope.RegisterParameter<string?>(nameof(Text))
// .WithParameter(() => Text)
Expand All @@ -41,8 +35,6 @@ protected MudBaseInputExtended()
// .WithChangeHandler(UpdateInputIdStateAsync);
}



/// <summary>
/// Fires on input.
/// </summary>
Expand Down Expand Up @@ -171,7 +163,5 @@ public async Task<bool> OnBeforeInputFromJs(BeforeInputJsDto dto)
/// <param name="args">An object containing event data for the input operation.</param>
/// <returns>A task that represents the asynchronous operation. The default implementation returns a completed task.</returns>
protected virtual Task OnBeforeInputAsync(BeforeInputEventArgs args) => Task.CompletedTask;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
OnClearButtonClick="@(async() => await OnClearButtonClick.InvokeAsync())"
OnDebounceIntervalElapsed="@(async() => await OnDebounceIntervalElapsed.InvokeAsync())"
OnInternalInputChanged="@(async() => await OnInternalInputChanged.InvokeAsync())"
ShrinkLabel="@(Values?.Any() ?? false)"
ShrinkLabel="@(_valuesState.Value?.Any() ?? false)"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule of parameter state. Always use the backing field, no exceptions

Clearable="@Clearable"
AutoFocus="@AutoFocus"
Class="@Class"
Expand Down Expand Up @@ -43,19 +43,19 @@
Variant="@Variant"
@bind-Value="@_internalValue"
TextChanged="@(async() => await TextChanged.InvokeAsync())"
ShowVisualiser="@(Values?.Any() ?? false)">
ShowVisualiser="@(_valuesState.Value?.Any() ?? false)">

<DataVisualiser>
<MudChipSet T="T" Class="@ChipClassname" Style="@ChipStylename" AllClosable="@Closeable" OnClose="Closed">
@for (int i = 0; i < (MaxChips == 0 ? Values?.Count ?? 0 : (MaxChips < (Values?.Count ?? 0) ? MaxChips : Values?.Count ?? 0)); i++)
@for (int i = 0; i < (MaxChips == 0 ? _valuesState.Value?.Count ?? 0 : (MaxChips < (_valuesState.Value?.Count ?? 0) ? MaxChips : _valuesState.Value?.Count ?? 0)); i++)
{
int a = i;
<MudChip T="T" Class="@ClassChip" Style="@StyleChip" Ripple="false" Text="@(Values != null ? Values[a] : string.Empty)" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
<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" />
}
</MudChipSet>
@if (Values != null && MaxChips != 0 && MaxChips < Values.Count)
@if (_valuesState.Value != null && MaxChips != 0 && MaxChips < _valuesState.Value.Count)
{
<MudChip T="T" Ripple="false" Text="@($"+{Values.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
<MudChip T="T" Ripple="false" Text="@($"+{_valuesState.Value.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
}
</DataVisualiser>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/// <summary>
/// /The list of values.
/// </summary>
[Parameter]
[Parameter, ParameterState]
public List<string>? Values { get; set; }

/// <summary>
Expand Down Expand Up @@ -134,7 +134,7 @@
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
protected internal async Task HandleKeyDown(KeyboardEventArgs args)
protected internal Task HandleKeyDown(KeyboardEventArgs args)
{
//var result = args.Key;
//if (result.Equals(Delimiter, StringComparison.InvariantCultureIgnoreCase) && _internalValue != null)
Expand All @@ -158,17 +158,17 @@
//}
//await Task.Delay(10);
//await SetValueAsync(_internalValue);
await OnKeyDown.InvokeAsync(args);
return OnKeyDown.InvokeAsync(args);
}

/// <summary>
/// Protected keyup event.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
protected async Task HandleKeyUp(KeyboardEventArgs args)
protected Task HandleKeyUp(KeyboardEventArgs args)
{
await OnKeyUp.InvokeAsync(args);
return OnKeyUp.InvokeAsync(args);
}

/// <summary>
Expand All @@ -186,7 +186,7 @@
if (args.IsInsert && args.Data == Delimiter && _internalValue is not null)
{
args.PreventDefault = true;
var currentText = base.ConvertSet(_internalValue);
var currentText = ConvertSet(_internalValue);

if (!string.IsNullOrEmpty(currentText))
{
Expand All @@ -200,7 +200,7 @@
return;
}

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

Expand All @@ -222,9 +222,9 @@

foreach (var part in parts)
{
if (AllowSameValues || !_valuesState.Value.Contains(part))

Check warning on line 225 in src/CodeBeam.MudBlazor.Extensions/Components/ChipField/MudChipField.razor.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
_valuesState.Value.Add(part);

Check warning on line 227 in src/CodeBeam.MudBlazor.Extensions/Components/ChipField/MudChipField.razor.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}

Expand All @@ -247,7 +247,7 @@
{
await _valuesState.SetValueAsync(new List<string>());
}
_valuesState.Value.Add(base.ConvertSet(_internalValue) ?? "");
_valuesState.Value.Add(ConvertSet(_internalValue) ?? "");

Check warning on line 250 in src/CodeBeam.MudBlazor.Extensions/Components/ChipField/MudChipField.razor.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
await ValuesChanged.InvokeAsync(_valuesState.Value);
if (RuntimeLocation.IsServerSide)
{
Expand Down Expand Up @@ -290,6 +290,5 @@
{
await _textFieldExtendedReference.Clear();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<MudInputControl Class="@Class" Style="@Style" Error="@ErrorState.Value" ErrorText="@GetErrorText()" Required="false">
<InputContent>
<div class="@Classname" style="@InnerStyle">
@for (int i = 0; i < Count; i++)
@for (int i = 0; i < _count.Value; i++)
{
int a = i;
<MudTextFieldExtended @ref="_elementReferences[a]" T="T" Class="@InputClassname" Style="@(Margin == Margin.Dense ? "width: 32px" : "width: 42px")" MaxLength="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async Task OnCountChanged()
/// <summary>
/// The value of the input.
/// </summary>
[Parameter]
[Parameter, ParameterState]
[Category(CategoryTypes.FormComponent.Behavior)]
public T? Value { get; set; }

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

Expand Down Expand Up @@ -218,7 +218,7 @@ protected async Task CheckFocus(int count)
_skipRefocus = false;
return;
}
string str = base.ConvertSet(_theValue.Value) ?? string.Empty;
string str = ConvertSet(_theValue.Value) ?? string.Empty;
await _elementReferences[str.Length].FocusAsync();
}

Expand Down Expand Up @@ -298,7 +298,7 @@ public async Task SetValue()
/// <returns></returns>
public async Task SetValueFromOutside(T? value)
{
string? val = base.ConvertSet(value);
string? val = ConvertSet(value);
if (_count.Value < val?.Length)
{
val = val.Substring(0, _count.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{
foreach (var item in CollectionsMarshal.AsSpan(collection))
{
<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)"
<MudChip Class="@ChipClass" Value="@item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? ConvertSet(item.Value) : item.Text)"
Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation />
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/// <param name="value"></param>
protected internal void SetSearchString(T value)
{
_searchString = base.ConvertSet(value);
_searchString = ConvertSet(value);
}

internal string? _searchString { get; set; }
Expand Down Expand Up @@ -537,7 +537,7 @@
}
else
{
if (ReadValue is string && string.IsNullOrWhiteSpace(base.ConvertSet(ReadValue)))
if (ReadValue is string && string.IsNullOrWhiteSpace(ConvertSet(ReadValue)))
{
SelectedValues = new HashSet<T?>();
}
Expand All @@ -552,7 +552,7 @@
else
{
await SetValueAndUpdateTextAsync(SelectedValues.LastOrDefault(), false);
_searchString = base.ConvertSet(SelectedValues.LastOrDefault());
_searchString = ConvertSet(SelectedValues.LastOrDefault());
}
}

Expand All @@ -571,7 +571,7 @@
return;
_comparer = value;
// Apply comparer and refresh selected values
_selectedValues = new HashSet<T?>(_selectedValues, _comparer);

Check warning on line 574 in src/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'collection' in 'HashSet<T?>.HashSet(IEnumerable<T?> collection, IEqualityComparer<T?>? comparer)'.
SelectedValues = _selectedValues;
}
}
Expand Down Expand Up @@ -618,7 +618,7 @@

_selectedValues = new HashSet<T?>(set, _comparer);

SelectedValuesChanged.InvokeAsync(new HashSet<T?>(SelectedValues, _comparer)).CatchAndLog();

Check warning on line 621 in src/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'collection' in 'HashSet<T?>.HashSet(IEnumerable<T?> collection, IEqualityComparer<T?>? comparer)'.
ForceUpdateItems().CatchAndLog();
//Console.WriteLine("SelectedValues setter ended");
}
Expand Down Expand Up @@ -655,13 +655,13 @@
{
if (!Strict && !Items.Select(x => x.Value).Contains(val))
{
textList.Add(ToStringFunc != null ? ToStringFunc(val) : base.ConvertSet(val));
Comment thread
mckaragoz marked this conversation as resolved.
textList.Add(ConvertSet(val));
continue;
}
var item = Items.FirstOrDefault(x => x != null && (x.Value == null ? val == null : Comparer != null ? Comparer.Equals(x.Value, val) : x.Value.Equals(val)));
if (item != null)
{
textList.Add(!string.IsNullOrWhiteSpace(item.Text) ? item.Text : base.ConvertSet(item.Value));
textList.Add(!string.IsNullOrWhiteSpace(item.Text) ? item.Text : ConvertSet(item.Value));
}
}
}
Expand Down Expand Up @@ -691,8 +691,8 @@
{
var item = Items?.FirstOrDefault(x => ReadValue == null ? x.Value == null : Comparer != null ? Comparer.Equals(ReadValue, x.Value) : ReadValue.Equals(x.Value));
_dataVisualiserText = item is null
? base.ConvertSet(ReadValue)
: (!string.IsNullOrWhiteSpace(item.Text) ? item.Text : base.ConvertSet(item.Value));
? ConvertSet(ReadValue)
: (!string.IsNullOrWhiteSpace(item.Text) ? item.Text : ConvertSet(item.Value));

return Task.CompletedTask;
}
Expand All @@ -711,7 +711,7 @@
await SetValueAndUpdateTextAsync(value, updateText, force);
if (updateSearchString)
{
_searchString = base.ConvertSet(ReadValue);
_searchString = ConvertSet(ReadValue);
await _inputReference.SetText(_searchString);
}
}
Expand Down Expand Up @@ -809,7 +809,7 @@
await ForceUpdateItems();
if (MultiSelection == false)
{
_searchString = base.ConvertSet(ReadValue);
_searchString = ConvertSet(ReadValue);
if (_inputReference != null)
{
await _inputReference?.SetText(_searchString);
Expand Down Expand Up @@ -1052,7 +1052,7 @@
if (Strict)
{
// Check if the user-provided search string is an exact (case-insensitive) match against an item in the collection.
var item = Items.FirstOrDefault(x => base.ConvertSet(x.Value)?.Equals(_searchString, StringComparison.OrdinalIgnoreCase) == true);
var item = Items.FirstOrDefault(x => ConvertSet(x.Value)?.Equals(_searchString, StringComparison.OrdinalIgnoreCase) == true);
if (item is not null)
await ToggleOption(item, true);

Expand Down Expand Up @@ -1550,7 +1550,7 @@


// Get a collection of items that start with "firstLetter".
var items = Items.Where(x => base.ConvertSet(x.Value)?.StartsWith(firstLetter, StringComparison.OrdinalIgnoreCase) == true).ToList();
var items = Items.Where(x => ConvertSet(x.Value)?.StartsWith(firstLetter, StringComparison.OrdinalIgnoreCase) == true).ToList();
if (!items.Any())
{
if (_lastActivatedItem is not null)
Expand Down Expand Up @@ -1701,5 +1701,18 @@
///
/// </summary>
protected internal Color EffectiveCheckBoxUnCheckedColor => CheckBoxUnCheckedColor ?? Color;

/// <inheritdoc />
protected override string? ConvertSet(T? input) => ConverterSetCore(input);

internal string? ConverterSetCore(T? input)
{
if (ToStringFunc is null)
{
return base.ConvertSet(input);
}

return ToStringFunc(input);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudBlazor.Extensions;
using MudBlazor.Utilities;
using MudBlazor.Extensions;

namespace MudExtensions
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public partial class MudComboBoxItem<T> : MudComponentBase, IDisposable
/// The parent select component
/// </summary>
[CascadingParameter]
MudComboBox<T> MudComboBox { get; set; } = null!;
private MudComboBox<T>? MudComboBox { get; set; }

/// <summary>
/// Prevents the user from interacting with this item.
Expand Down Expand Up @@ -150,17 +150,17 @@ protected string? DisplayString
{
get
{
var converter = MudComboBox?.Converter;
if (MudComboBox?.ItemPresenter == ValuePresenter.None)
{
if (converter == null)
return Value?.ToString();
return converter.Convert(Value);
}

if (converter == null)
return $"{(string.IsNullOrWhiteSpace(Text) ? Value : Text)}";
return !string.IsNullOrWhiteSpace(Text) ? Text : converter.Convert(Value);
var hasText = !string.IsNullOrWhiteSpace(Text);

if (MudComboBox == null)
return hasText ? Text : Value?.ToString();

if (MudComboBox.ItemPresenter == ValuePresenter.None)
return MudComboBox.ConverterSetCore(Value);

return hasText
? Text
: MudComboBox.ConverterSetCore(Value);
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ protected bool IsEligible()
}
else
{
if (MudComboBox?.Converter?.Convert(Value)?.Contains(MudComboBox._searchString ?? string.Empty, StringComparison.OrdinalIgnoreCase) == true)
if (MudComboBox?.ConverterSetCore(Value)?.Contains(MudComboBox._searchString ?? string.Empty, StringComparison.OrdinalIgnoreCase) == true)
return true;
}

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

else if (MudComboBox?.MultiSelection == false && ((MudComboBox.Value is null && Value is null) || MudComboBox.Value?.Equals(Value) == true))
else if (MudComboBox?.MultiSelection == false && ((MudComboBox.GetState(x => x.Value) is null && Value is null) || MudComboBox.GetState(x => x.Value)?.Equals(Value) == true))
Selected = true;
else
Selected = false;
Expand All @@ -289,9 +289,13 @@ protected void SyncSelected()
/// <returns></returns>
protected async Task HandleOnClick()
{
await MudComboBox.ToggleOption(this, !Selected);
await InvokeAsync(StateHasChanged);
await MudComboBox.FocusAsync();
if (MudComboBox is not null)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that in many places MudComboBox has a null check but not here, and for some reason the MudComboBox wasn't declared as null possible, but as null!, you need to decide here. Can it be null or not? If not then you can remove the null checks everywhere.

{
await MudComboBox.ToggleOption(this, !Selected);
await InvokeAsync(StateHasChanged);
await MudComboBox.FocusAsync();
}

await OnClick.InvokeAsync();
}

Expand Down
Loading
Loading