Skip to content

Commit fce43e8

Browse files
committed
Revert "wip: 临时提交"
This reverts commit d841341.
1 parent 1c76aef commit fce43e8

3 files changed

Lines changed: 49 additions & 75 deletions

File tree

src/BootstrapBlazor/Components/Tab/Tab.razor

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ else
149149
@ContextMenuTemplate(this)
150150
}
151151
</ContextMenu>;
152-
152+
153153
RenderFragment<TabItem> RenderTabItem => item =>
154154
@<CascadingValue Value="item" IsFixed="true">
155155
@RenderTabItemContent(item)
156156
</CascadingValue>;
157157

158-
RenderFragment RenderDisabledHeaderItem(TabItem item) =>
158+
RenderFragment RenderDisabledHeaderItem(TabItem item) =>
159159
@<div @key="@item" class="@GetItemWrapClassString(item)">
160-
<div role="tab" class="@GetClassString(item)"
160+
<div role="tab" class="@GetClassString(item)"
161161
@oncontextmenu="e => OnContextMenu(e, item)" @oncontextmenu:preventDefault="IsPreventDefault">
162162
@RenderHeaderItemContent(item)
163163
</div>
@@ -170,7 +170,11 @@ else
170170

171171
RenderFragment RenderHeaderItem(TabItem item) =>
172172
@<div @key="@item" class="@GetItemWrapClassString(item)" draggable="@DraggableString">
173-
@RenderHeaderLinkItem(item)
173+
<DynamicElement TagName="a" href="@item.Url" role="tab" tabindex="-1" class="@GetClassString(item)"
174+
OnContextMenu="e => OnContextMenu(e, item)"
175+
OnClick="@(() => OnClickTabItem(item))">
176+
@RenderHeaderItemContent(item)
177+
</DynamicElement>
174178
@if (TabStyle == TabStyle.Chrome)
175179
{
176180
<i class="tab-corner tab-corner-left"></i>

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,19 @@ protected override void OnParametersSet()
534534
TabStyle = TabStyle.Default;
535535
}
536536

537-
AddTabByUrl();
537+
if (ClickTabToNavigation)
538+
{
539+
if (!HandlerNavigation)
540+
{
541+
HandlerNavigation = true;
542+
Navigator.LocationChanged += Navigator_LocationChanged;
543+
}
544+
AddTabByUrl();
545+
}
546+
else
547+
{
548+
RemoveLocationChanged();
549+
}
538550
}
539551

540552
/// <summary>
@@ -569,6 +581,22 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
569581
/// <returns></returns>
570582
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, nameof(DragItemCallback));
571583

584+
private void RemoveLocationChanged()
585+
{
586+
if (HandlerNavigation)
587+
{
588+
Navigator.LocationChanged -= Navigator_LocationChanged;
589+
HandlerNavigation = false;
590+
}
591+
}
592+
593+
private void Navigator_LocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
594+
{
595+
AddTabByUrl();
596+
InvokeUpdate = true;
597+
StateHasChanged();
598+
}
599+
572600
private void AddTabByUrl()
573601
{
574602
var requestUrl = Navigator.ToBaseRelativePath(Navigator.Uri);
@@ -595,12 +623,23 @@ private void AddTabByUrl()
595623

596624
private bool ShouldShowExtendButtons() => ShowExtendButtons && (Placement == Placement.Top || Placement == Placement.Bottom);
597625

626+
/// <summary>
627+
/// 点击 TabItem 时回调此方法
628+
/// </summary>
598629
private async Task OnClickTabItem(TabItem item)
599630
{
600631
if (OnClickTabItemAsync != null)
601632
{
602633
await OnClickTabItemAsync(item);
603634
}
635+
636+
if (!ClickTabToNavigation)
637+
{
638+
TabItems.ForEach(i => i.SetActive(false));
639+
item.SetActive(true);
640+
InvokeUpdate = true;
641+
StateHasChanged();
642+
}
604643
}
605644

606645
/// <summary>
@@ -1188,6 +1227,7 @@ protected override async ValueTask DisposeAsync(bool disposing)
11881227

11891228
if (disposing)
11901229
{
1230+
RemoveLocationChanged();
11911231
ErrorLogger?.UnRegister(this);
11921232
}
11931233
}

src/BootstrapBlazor/Components/Tab/TabHeader.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)