File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -106,9 +106,23 @@ export class TabButton implements ComponentInterface, AnchorInterface {
106106
107107 // Check if this tab button should be initially selected based on parent tab-bar's selectedTab prop
108108 // This handles the case where selected-tab is set via HTML attribute before events fire
109+ this . syncWithTabBar ( ) ;
110+ }
111+
112+ componentDidLoad ( ) {
113+ // Double-check selection state after load to handle any timing issues
114+ // This ensures the button reflects the correct state even if the initial check was too early
115+ this . syncWithTabBar ( ) ;
116+ }
117+
118+ private syncWithTabBar ( ) {
109119 const tabBar = this . el . parentElement as HTMLIonTabBarElement | null ;
110- if ( tabBar && tabBar . tagName === 'ION-TAB-BAR' && tabBar . selectedTab !== undefined ) {
111- this . selected = this . tab === tabBar . selectedTab ;
120+ if ( tabBar && tabBar . tagName === 'ION-TAB-BAR' ) {
121+ // Check both the property and attribute to handle all initialization scenarios
122+ const selectedTab = tabBar . selectedTab ?? tabBar . getAttribute ( 'selected-tab' ) ;
123+ if ( selectedTab !== null && selectedTab !== undefined ) {
124+ this . selected = this . tab === selectedTab ;
125+ }
112126 }
113127 }
114128
Original file line number Diff line number Diff line change @@ -75,10 +75,23 @@ export class Tabs implements NavOutlet {
7575
7676 private updateTabBar ( ) {
7777 const tabBar = this . el . querySelector ( 'ion-tab-bar' ) ;
78- if ( tabBar ) {
79- const tab = this . selectedTab ? this . selectedTab . tab : undefined ;
80- tabBar . selectedTab = tab ;
78+ if ( ! tabBar ) {
79+ return ;
80+ }
81+
82+ const tab = this . selectedTab ? this . selectedTab . tab : undefined ;
83+
84+ // If tabs has no selected tab but tab-bar already has a selected-tab set,
85+ // don't overwrite it. This handles cases where tab-bar is used without ion-tab elements.
86+ if ( tab === undefined ) {
87+ return ;
8188 }
89+
90+ if ( tabBar . selectedTab === tab ) {
91+ return ;
92+ }
93+
94+ tabBar . selectedTab = tab ;
8295 }
8396
8497 /**
You can’t perform that action at this time.
0 commit comments