-
Notifications
You must be signed in to change notification settings - Fork 101
Fix ParameterState & Converter usage #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
@@ -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> | ||
|
|
||
|
|
||
| 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 | ||
| { | ||
|
|
@@ -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. | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
|
@@ -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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| { | ||
| await MudComboBox.ToggleOption(this, !Selected); | ||
| await InvokeAsync(StateHasChanged); | ||
| await MudComboBox.FocusAsync(); | ||
| } | ||
|
|
||
| await OnClick.InvokeAsync(); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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>