Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/Core/Components/Tabs/FluentTabs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
/// </summary>
public partial class FluentTabs : FluentComponentBase
{
private string? _clientActiveTabId;
private bool _overflowInitialized;
private bool? _previousOverflowValue;
private bool _refreshOverflowAfterRender;
Expand Down Expand Up @@ -162,14 +161,7 @@ public FluentTabs(LibraryConfiguration configuration) : base(configuration)
/// <summary />
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;
}

/// <summary />
Expand Down Expand Up @@ -263,7 +255,6 @@ internal async Task<int> RemoveTabAsync(FluentTab? tab)
ActiveTab = firstTab;
ActiveTabId = firstTabId;
ActiveTabIdAttribute = firstTabId;
_clientActiveTabId = null;

if (ActiveTabChanged.HasDelegate)
{
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -348,7 +339,7 @@ public override async ValueTask DisposeAsync()
/// <summary>
/// Sets the specified tab as the active tab.
/// </summary>
private async Task<bool> SetActiveTabAsync(FluentTab? tab, bool updateActiveIdAttribute = true)
private async Task<bool> SetActiveTabAsync(FluentTab? tab)
{
if (tab is null || Disabled || tab.Disabled || !tab.Visible)
{
Expand All @@ -364,18 +355,9 @@ private async Task<bool> 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);
Expand Down
31 changes: 29 additions & 2 deletions tests/Core/Components/Tabs/FluentTabsTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}

[Fact]
public async Task FluentTabs_UserSelection_DoesNotRewriteActiveId()
public async Task FluentTabs_UserSelection_SynchronizesActiveId()
{
string? activeTabId = "tab1";

Expand All @@ -96,7 +96,7 @@

// Assert
Assert.Equal("tab2", activeTabId);
Assert.Equal("tab1", tabList.GetAttribute("activeid"));
Assert.Equal("tab2", tabList.GetAttribute("activeid"));
}

[Fact]
Expand Down Expand Up @@ -125,6 +125,33 @@
Assert.Equal("tab3", tabList.GetAttribute("activeid"));
}

[Fact]
public async Task FluentTabs_ParameterSelection_ReappliesPreviousValueAfterUserSelection()
{
string? activeTabId = "tab1";

// Arrange
var cut = Render(@<FluentTabs Id="MyTabsId" @bind-ActiveTabId="@activeTabId">
<FluentTab Id="tab1" Header="Chat" />
<FluentTab Id="tab2" Header="Files" />
</FluentTabs>);
var tabs = cut.FindComponent<FluentTabs>();
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)]
Expand Down
Loading