Skip to content

Commit 534a888

Browse files
authored
🐛 fix(Tab): matching route is not highlighted correctly (#611)
1 parent da8d480 commit 534a888

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/Component/BlazorComponent/Components/ItemGroup/BRoutableGroupItem.razor.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ public BRoutableGroupItem(GroupType groupType, string defaultTag = "div") : base
4444

4545
protected override async Task OnInitializedAsync()
4646
{
47-
await base.OnInitializedAsync();
47+
if (IsRoutable)
48+
{
49+
Router = new Router(this);
50+
Value = Href;
51+
await UpdateActiveForRoutable();
52+
NavigationManager.LocationChanged += OnLocationChanged;
53+
}
4854

49-
Router = new Router(this);
50-
await UpdateActiveForRoutable();
51-
NavigationManager.LocationChanged += OnLocationChanged;
55+
await base.OnInitializedAsync();
5256
}
5357

5458
protected override void OnParametersSet()
5559
{
5660
base.OnParametersSet();
5761

5862
Router = new Router(this);
59-
6063
(Tag, Attributes) = Router.GenerateRouteLink();
6164
}
6265

@@ -71,7 +74,7 @@ private async void OnLocationChanged(object? sender, LocationChangedEventArgs e)
7174

7275
private async Task<bool> UpdateActiveForRoutable()
7376
{
74-
if (!IsRoutable || Router is null) return false;
77+
if (Router is null) return false;
7578

7679
var isActive = InternalIsActive;
7780

@@ -89,8 +92,11 @@ private async Task<bool> UpdateActiveForRoutable()
8992

9093
protected override ValueTask DisposeAsyncCore()
9194
{
92-
NavigationManager.LocationChanged -= OnLocationChanged;
95+
if (IsRoutable)
96+
{
97+
NavigationManager.LocationChanged -= OnLocationChanged;
98+
}
9399

94100
return base.DisposeAsyncCore();
95101
}
96-
}
102+
}

src/Component/BlazorComponent/Components/ItemGroup/ItemGroupBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void RefreshItemsState()
7272
Items.ForEach(item => item.RefreshState());
7373
}
7474

75-
protected virtual StringNumber InitDefaultItemValue()
75+
protected StringNumber InitDefaultItemValue()
7676
{
7777
return _registeredItemsIndex++;
7878
}

src/Component/BlazorComponent/Components/Tabs/BTab.razor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ public BTab() : base(GroupType.SlideGroup)
66
{
77
}
88

9-
[CascadingParameter]
10-
public BTabs? Tabs { get; set; }
9+
[CascadingParameter] public BTabs? Tabs { get; set; }
1110

1211
protected override bool HasRoutableAncestor => Tabs?.Routable is true;
1312

@@ -17,12 +16,15 @@ public BTab() : base(GroupType.SlideGroup)
1716

1817
private async Task HandleOnClick(MouseEventArgs args)
1918
{
20-
await ToggleAsync();
19+
if (!IsRoutable)
20+
{
21+
await ToggleAsync();
22+
}
2123

2224
if (OnClick.HasDelegate)
2325
{
2426
await OnClick.InvokeAsync(args);
2527
}
2628
}
2729
}
28-
}
30+
}

src/Component/BlazorComponent/Mixins/Groupable/BGroupable.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ protected BGroupable(GroupType groupType, bool bootable) : this(groupType)
9393

9494
protected virtual bool HasTransition { get; } = false;
9595

96-
protected override void OnInitialized()
96+
protected override async Task OnInitializedAsync()
9797
{
98-
base.OnInitialized();
99-
10098
if (!Matched) return;
10199

102100
if (this is IGroupable item)
103101
{
104102
ItemGroup!.Register(item);
105103
}
104+
105+
await base.OnInitializedAsync();
106106
}
107107

108108
protected override async Task OnParametersSetAsync()

0 commit comments

Comments
 (0)