Skip to content
27 changes: 1 addition & 26 deletions src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components;
/// <para lang="zh">动态元素组件</para>
/// <para lang="en">Dynamic element component</para>
/// </summary>
public class DynamicElement : BootstrapComponentBase, IAsyncDisposable
public class DynamicElement : BootstrapComponentBase
{
/// <summary>
/// <para lang="zh">获得/设置 TagName 属性 默认为 div</para>
Expand Down Expand Up @@ -176,29 +176,4 @@ private async Task OnTriggerContextMenu(MouseEventArgs e)
await OnContextMenu(e);
}
}

/// <summary>
/// <para lang="zh">异步释放资源</para>
/// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
/// </summary>
/// <param name="disposing"></param>
protected virtual async ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
OnClick = null;
OnDoubleClick = null;
OnContextMenu = null;
ChildContent = null;
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
public async ValueTask DisposeAsync()
{
await DisposeAsync(true);
GC.SuppressFinalize(this);
}
}
10 changes: 0 additions & 10 deletions src/BootstrapBlazor/Components/Button/ButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,6 @@ protected override async ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
if (OnClick.HasDelegate)
{
OnClick = EventCallback<MouseEventArgs>.Empty;
}

if (OnClickWithoutRender != null)
{
OnClickWithoutRender = null;
}

if (IsAsync && ValidateForm != null)
{
ValidateForm.UnregisterAsyncSubmitButton(this);
Expand Down
9 changes: 4 additions & 5 deletions src/BootstrapBlazor/Components/Select/Select.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@using Microsoft.AspNetCore.Components.Web.Virtualization
@typeparam TValue
@inherits SimpleSelectBase<TValue>
Expand All @@ -22,8 +22,7 @@
}
else
{
<input type="text" id="@InputId" disabled="@Disabled" placeholder="@PlaceHolder" class="@InputClassString"
value="@SelectedRow?.Text" @onchange="@_onChangeEventCallback" readonly="@ReadonlyString" />
<input type="text" id="@InputId" disabled="@Disabled" placeholder="@PlaceHolder" class="@InputClassString" value="@SelectedRow?.Text" @onchange="OnChange" readonly="@ReadonlyString" />
}
<span class="@AppendClassString"><i class="@DropdownIcon"></i></span>
</div>
Expand Down Expand Up @@ -93,7 +92,7 @@

@code {
RenderFragment<SelectedItem> RenderRow => item =>
@<DynamicElement class="@ActiveItem(item)" OnClick="() => OnClickItem(item)">
@<div class="@ActiveItem(item)" @onclick="() => OnClickItem(item)">
@if (ItemTemplate != null)
{
@ItemTemplate(item)
Expand All @@ -106,7 +105,7 @@
{
@item.Text
}
</DynamicElement>;
</div>;

RenderFragment<PlaceholderContext> RenderPlaceHolderRow => context =>
@<div class="dropdown-item">
Expand Down
25 changes: 1 addition & 24 deletions src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ public bool IsUseActiveWhenValueIsNull

private string _defaultVirtualizedItemText = "";

private EventCallback<ChangeEventArgs> _onChangeEventCallback = EventCallback<ChangeEventArgs>.Empty;

private SelectedItem? SelectedItem { get; set; }

private SelectedItem? SelectedRow
Expand Down Expand Up @@ -236,10 +234,6 @@ protected override void OnParametersSet()
NoSearchDataText ??= Localizer[nameof(NoSearchDataText)];
DropdownIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectDropdownIcon);
ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon);

_onChangeEventCallback = IsEditable
? EventCallback.Factory.Create<ChangeEventArgs>(this, OnChange)
: EventCallback<ChangeEventArgs>.Empty;
}

/// <summary>
Expand Down Expand Up @@ -395,8 +389,6 @@ private async Task OnClickItem(SelectedItem item)
_defaultVirtualizedItemText = item.Text;
await SelectedItemChanged(item);
}

StateHasChanged();
}

private async Task SelectedItemChanged(SelectedItem item)
Expand Down Expand Up @@ -502,26 +494,11 @@ private async Task OnChange(ChangeEventArgs args)
// 修复:使用完整的未过滤列表来查找当前选中项
// 避免在用户搜索时被外部 StateHasChanged 影响导致值被错误修改
var allItems = GetRowsByItems();

var item = GetItemWithEnumValue()
?? allItems.Find(i => i.Value == CurrentValueAsString)
?? allItems.Find(i => i.Active)
?? allItems.Find(i => !i.IsDisabled);
return item;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="disposing"></param>
/// <returns></returns>
protected override ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
_onChangeEventCallback = EventCallback<ChangeEventArgs>.Empty;
}

return base.DisposeAsync(disposing);
}
}
Loading