!3747 fix(#I69VFA): update RibbonTab make sure have IsActive item

* chore: bump version 7.2.3-beta02
* fix: 修复 RibbonTab 可能导致二级菜单不显示问题
This commit is contained in:
Argo 2023-01-10 14:06:14 +00:00
parent 18c42bd5f4
commit a85f81edf2
3 changed files with 23 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>7.2.3-beta01</Version>
<Version>7.2.3-beta02</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

View File

@ -4,7 +4,7 @@
<div @attributes="@AdditionalAttributes" id="@Id" class="@HeaderClassString">
<div class="ribbon-header">
<Tab IsBorderCard="true" OnClickTab="OnClickTab">
@foreach (var item in GetItems())
@foreach (var item in Items)
{
<TabItem @key="item" Text="@item.Text" IsActive="item.IsActive">
<div class="tab-commands">

View File

@ -52,6 +52,7 @@ public partial class RibbonTab
/// 获得/设置 数据源
/// </summary>
[Parameter]
[NotNull]
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
@ -106,6 +107,24 @@ public partial class RibbonTab
/// <returns></returns>
protected override Task ModuleInitAsync() => InvokeInitAsync(Id, nameof(SetExpand));
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();
Items ??= Enumerable.Empty<RibbonTabItem>();
if (!Items.Any(i => i.IsActive))
{
var item = Items.FirstOrDefault();
if (item != null)
{
item.IsActive = true;
}
}
}
/// <summary>
/// SetExpand 方法
/// </summary>
@ -126,12 +145,12 @@ public partial class RibbonTab
private async Task OnClickTab(TabItem item)
{
var tab = GetItems().FirstOrDefault(i => i.IsActive);
var tab = Items.FirstOrDefault(i => i.IsActive);
if (tab != null)
{
tab.IsActive = false;
}
tab = GetItems().First(i => i.Text == item.Text);
tab = Items.First(i => i.Text == item.Text);
tab.IsActive = true;
if (OnMenuClickAsync != null)
{
@ -144,8 +163,6 @@ public partial class RibbonTab
}
}
private IEnumerable<RibbonTabItem> GetItems() => Items ?? Enumerable.Empty<RibbonTabItem>();
private async Task OnToggleFloat()
{
IsFloat = !IsFloat;