22// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
33// ------------------------------------------------------------------------
44
5+ using System . Diagnostics . CodeAnalysis ;
6+ using System . Text . Json ;
57using Microsoft . AspNetCore . Components ;
68using Microsoft . FluentUI . AspNetCore . Components . Extensions ;
79using Microsoft . FluentUI . AspNetCore . Components . Utilities ;
810using Microsoft . JSInterop ;
9- using System . Diagnostics . CodeAnalysis ;
10- using System . Text . Json ;
1111
1212namespace Microsoft . FluentUI . AspNetCore . Components ;
1313
@@ -16,7 +16,7 @@ public partial class FluentTabs : FluentComponentBase
1616 private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Overflow/FluentOverflow.razor.js" ;
1717
1818 private const string FLUENT_TAB_TAG = "fluent-tab" ;
19- private readonly Dictionary < string , FluentTab > _tabs = [ ] ;
19+ private readonly List < FluentTab > _tabs = [ ] ;
2020 //private string _activeId = string.Empty;
2121 private DotNetObjectReference < FluentTabs > ? _dotNetHelper = null ;
2222 private IJSObjectReference _jsModuleOverflow = default ! ;
@@ -98,7 +98,7 @@ public partial class FluentTabs : FluentComponentBase
9898 /// <summary>
9999 /// Gets the active selected tab.
100100 /// </summary>
101- public FluentTab ActiveTab => _tabs . FirstOrDefault ( i => i . Key == ActiveTabId ) . Value ?? _tabs . First ( ) . Value ;
101+ public FluentTab ActiveTab => _tabs . FirstOrDefault ( t => t . Id == ActiveTabId ) ?? _tabs . First ( ) ;
102102
103103 [ Parameter ]
104104 public string ActiveTabId { get ; set ; } = default ! ;
@@ -135,7 +135,7 @@ public partial class FluentTabs : FluentComponentBase
135135 /// <summary>
136136 /// Gets all tabs with <see cref="FluentTab.Overflow"/> assigned to True.
137137 /// </summary>
138- public IEnumerable < FluentTab > TabsOverflow => _tabs . Where ( i => i . Value . Overflow == true ) . Select ( v => v . Value ) ;
138+ public IEnumerable < FluentTab > TabsOverflow => _tabs . Where ( i => i . Overflow == true ) ;
139139
140140 [ DynamicDependency ( DynamicallyAccessedMemberTypes . All , typeof ( TabChangeEventArgs ) ) ]
141141
@@ -154,41 +154,47 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
154154 _jsModuleOverflow = await JSRuntime . InvokeAsync < IJSObjectReference > ( "import" , JAVASCRIPT_FILE . FormatCollocatedUrl ( LibraryConfiguration ) ) ;
155155
156156 var horizontal = Orientation == Orientation . Horizontal ;
157- await _jsModuleOverflow . InvokeVoidAsync ( "fluentOverflowInitialize" , _dotNetHelper , Id , horizontal , FLUENT_TAB_TAG , 25 ) ;
157+ await _jsModuleOverflow . InvokeVoidAsync ( "fluentOverflowInitialize" , _dotNetHelper , Id , horizontal , FLUENT_TAB_TAG , 25 ) ;
158158 }
159159 }
160160
161161 private async Task HandleOnTabChangedAsync ( TabChangeEventArgs args )
162162 {
163163 var tabId = args ? . ActiveId ;
164- if ( tabId is not null && _tabs . TryGetValue ( tabId , out FluentTab ? tab ) )
164+ var tab = _tabs . FirstOrDefault ( i => i . Id == tabId ) ;
165+
166+ if ( tab is not null && _tabs . Contains ( tab ) )
165167 {
166168 await OnTabChange . InvokeAsync ( tab ) ;
167- ActiveTabId = tabId ;
168- await ActiveTabIdChanged . InvokeAsync ( tabId ) ;
169+ if ( tabId != null )
170+ {
171+ ActiveTabId = tabId ;
172+ await ActiveTabIdChanged . InvokeAsync ( tabId ) ;
173+ }
169174 }
170175 }
171176
172177 internal int RegisterTab ( FluentTab tab )
173178 {
174- _ = _tabs . TryAdd ( tab . Id ! , tab ) ;
179+ _tabs . Add ( tab ) ;
175180 return _tabs . Count - 1 ;
176181 }
177182
178- internal async Task UnregisterTabAsync ( FluentTab tab )
183+ internal async Task UnregisterTabAsync ( string id )
179184 {
180185 if ( OnTabClose . HasDelegate )
181186 {
187+ var tab = _tabs . FirstOrDefault ( t => t . Id == id ) ;
182188 await OnTabClose . InvokeAsync ( tab ) ;
183189 }
184190
185191 if ( _tabs . Count > 0 )
186192 {
187- _tabs . Remove ( tab . Id ! ) ;
193+ _tabs . RemoveAt ( _tabs . Count - 1 ) ;
188194 }
189195
190196 // Set the first tab active
191- FluentTab ? firstTab = _tabs . FirstOrDefault ( ) . Value ;
197+ var firstTab = _tabs . FirstOrDefault ( ) ;
192198 if ( firstTab is not null )
193199 {
194200 await ResizeTabsForOverflowButtonAsync ( ) ;
@@ -228,9 +234,9 @@ public async Task OverflowRaisedAsync(string value)
228234 }
229235
230236 // Update Item components
231- foreach ( OverflowItem item in items )
237+ foreach ( var item in items )
232238 {
233- FluentTab ? tab = _tabs . FirstOrDefault ( i => i . Value . Id == item . Id ) . Value ;
239+ var tab = _tabs . FirstOrDefault ( i => i . Id == item . Id ) ;
234240 tab ? . SetProperties ( item . Overflow ) ;
235241 }
236242
0 commit comments