Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Bugfix/searchtext disappears #291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
22 changes: 17 additions & 5 deletions src/Blazored.Typeahead/BlazoredTypeahead.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@ public partial class BlazoredTypeahead<TItem, TValue> : ComponentBase, IDisposab
private bool _eventsHookedUp = false;
private ElementReference _searchInput;
private ElementReference _mask;
private IEqualityComparer<TValue> _valueComparer = EqualityComparer<TValue>.Default;

[Inject] private IJSRuntime JSRuntime { get; set; }

[CascadingParameter] private EditContext CascadedEditContext { get; set; }

[Parameter] public TValue Value { get; set; }
private TValue _value;
[Parameter] public TValue Value
{
get => _value;
set
{
if (_valueComparer.Equals(_value, value) == false)
{
_value = value;
Initialize();
}
}
}
[Parameter] public EventCallback<TValue> ValueChanged { get; set; }
[Parameter] public Expression<Func<TValue>> ValueExpression { get; set; }

Expand Down Expand Up @@ -130,7 +143,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

protected override void OnParametersSet()
{
Initialize();
}

private void Initialize()
Expand All @@ -143,7 +155,7 @@ private void Initialize()
private async Task RemoveValue(TValue item)
{
var valueList = Values ?? new List<TValue>();
if (valueList.Contains(item))
if (valueList.Contains(item, _valueComparer))
{
valueList.Remove(item);
}
Expand Down Expand Up @@ -409,7 +421,7 @@ private async Task SelectResult(TItem item)
{
var valueList = Values ?? new List<TValue>();

if (valueList.Contains(value))
if (valueList.Contains(value, _valueComparer))
valueList.Remove(value);
else
valueList.Add(value);
Expand All @@ -418,7 +430,7 @@ private async Task SelectResult(TItem item)
}
else
{
if (Value != null && Value.Equals(value)) return;
if (_valueComparer.Equals(Value, value)) return;
Value = value;
await ValueChanged.InvokeAsync(value);
}
Expand Down