diff --git a/src/Core/Components/Tabs/FluentTabs.razor.cs b/src/Core/Components/Tabs/FluentTabs.razor.cs
index 58b65d2495..9e4036bcb0 100644
--- a/src/Core/Components/Tabs/FluentTabs.razor.cs
+++ b/src/Core/Components/Tabs/FluentTabs.razor.cs
@@ -14,7 +14,6 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
///
public partial class FluentTabs : FluentComponentBase
{
- private string? _clientActiveTabId;
private bool _overflowInitialized;
private bool? _previousOverflowValue;
private bool _refreshOverflowAfterRender;
@@ -162,14 +161,7 @@ public FluentTabs(LibraryConfiguration configuration) : base(configuration)
///
protected override void OnParametersSet()
{
- var activeTabId = ActiveTabId ?? ActiveTab?.Id;
- if (string.Equals(activeTabId, _clientActiveTabId, StringComparison.Ordinal))
- {
- return;
- }
-
- ActiveTabIdAttribute = activeTabId;
- _clientActiveTabId = null;
+ ActiveTabIdAttribute = ActiveTabId ?? ActiveTab?.Id;
}
///
@@ -263,7 +255,6 @@ internal async Task RemoveTabAsync(FluentTab? tab)
ActiveTab = firstTab;
ActiveTabId = firstTabId;
ActiveTabIdAttribute = firstTabId;
- _clientActiveTabId = null;
if (ActiveTabChanged.HasDelegate)
{
@@ -296,7 +287,7 @@ internal async Task TabChangeHandlerAsync(TabChangeEventArgs args)
// Search for the tab
var tab = Tabs.FirstOrDefault(t => string.Equals(t.Id, args.ActiveId, StringComparison.Ordinal));
- await SetActiveTabAsync(tab, updateActiveIdAttribute: false);
+ await SetActiveTabAsync(tab);
}
///
@@ -348,7 +339,7 @@ public override async ValueTask DisposeAsync()
///
/// Sets the specified tab as the active tab.
///
- private async Task SetActiveTabAsync(FluentTab? tab, bool updateActiveIdAttribute = true)
+ private async Task SetActiveTabAsync(FluentTab? tab)
{
if (tab is null || Disabled || tab.Disabled || !tab.Visible)
{
@@ -364,18 +355,9 @@ private async Task SetActiveTabAsync(FluentTab? tab, bool updateActiveIdAt
ActiveTabId = tab.Id;
ActiveTab = tab;
+ ActiveTabIdAttribute = tab.Id;
_refreshOverflowAfterRender = Overflow;
- if (updateActiveIdAttribute)
- {
- ActiveTabIdAttribute = tab.Id;
- _clientActiveTabId = null;
- }
- else
- {
- _clientActiveTabId = tab.Id;
- }
-
if (activeTabIdChanged && ActiveTabIdChanged.HasDelegate)
{
await ActiveTabIdChanged.InvokeAsync(ActiveTabId);
diff --git a/tests/Core/Components/Tabs/FluentTabsTests.razor b/tests/Core/Components/Tabs/FluentTabsTests.razor
index 72cb1b92fb..3ec1080175 100644
--- a/tests/Core/Components/Tabs/FluentTabsTests.razor
+++ b/tests/Core/Components/Tabs/FluentTabsTests.razor
@@ -76,7 +76,7 @@
}
[Fact]
- public async Task FluentTabs_UserSelection_DoesNotRewriteActiveId()
+ public async Task FluentTabs_UserSelection_SynchronizesActiveId()
{
string? activeTabId = "tab1";
@@ -96,7 +96,7 @@
// Assert
Assert.Equal("tab2", activeTabId);
- Assert.Equal("tab1", tabList.GetAttribute("activeid"));
+ Assert.Equal("tab2", tabList.GetAttribute("activeid"));
}
[Fact]
@@ -125,6 +125,33 @@
Assert.Equal("tab3", tabList.GetAttribute("activeid"));
}
+ [Fact]
+ public async Task FluentTabs_ParameterSelection_ReappliesPreviousValueAfterUserSelection()
+ {
+ string? activeTabId = "tab1";
+
+ // Arrange
+ var cut = Render(@
+
+
+ );
+ var tabs = cut.FindComponent();
+ var tabList = cut.Find("fluent-tablist");
+ tabs.Render(parameters => parameters.Add(component => component.ActiveTabId, "tab2"));
+ tabList.SetAttribute("activeid", "tab1");
+ await tabList.TriggerEventAsync("ontabchange", new TabChangeEventArgs
+ {
+ Id = "MyTabsId-tablist",
+ ActiveId = "tab1",
+ });
+
+ // Act
+ tabs.Render(parameters => parameters.Add(component => component.ActiveTabId, "tab2"));
+
+ // Assert
+ Assert.Equal("tab2", tabList.GetAttribute("activeid"));
+ }
+
[Theory]
[InlineData(true, false, true)]
[InlineData(false, true, true)]