@ionic/react 9.0.13 → 9.0.14-dev.11795647570.11455540
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -2321,6 +2321,7 @@ class IonTabs extends React.Component {
|
|
|
2321
2321
|
routerOutletRef = React.createRef();
|
|
2322
2322
|
selectTabHandler;
|
|
2323
2323
|
tabBarRef = React.createRef();
|
|
2324
|
+
tabsElRef = React.createRef();
|
|
2324
2325
|
ionTabContextState = {
|
|
2325
2326
|
activeTab: undefined,
|
|
2326
2327
|
selectTab: () => false,
|
|
@@ -2337,7 +2338,12 @@ class IonTabs extends React.Component {
|
|
|
2337
2338
|
super(props);
|
|
2338
2339
|
}
|
|
2339
2340
|
componentDidMount() {
|
|
2340
|
-
|
|
2341
|
+
/**
|
|
2342
|
+
* Without a router outlet, the tab bar does not switch tabs,
|
|
2343
|
+
* so its `selectTab` and active tab must not replace the ones
|
|
2344
|
+
* set for `ion-tabs` in `render`.
|
|
2345
|
+
*/
|
|
2346
|
+
if (this.ionTabContextState.hasRouterOutlet && this.tabBarRef.current) {
|
|
2341
2347
|
// Grab initial value
|
|
2342
2348
|
this.ionTabContextState.activeTab = this.tabBarRef.current.state.activeTab;
|
|
2343
2349
|
// Override method
|
|
@@ -2347,6 +2353,26 @@ class IonTabs extends React.Component {
|
|
|
2347
2353
|
this.ionTabContextState.selectTab = this.tabBarRef.current.selectTab;
|
|
2348
2354
|
}
|
|
2349
2355
|
}
|
|
2356
|
+
/**
|
|
2357
|
+
* Selects a tab on `ion-tabs` when it is used without a router outlet.
|
|
2358
|
+
* Returns `false` when no `ion-tab` has the given `tab`.
|
|
2359
|
+
*/
|
|
2360
|
+
selectTabWithoutRouter = (tab) => {
|
|
2361
|
+
const tabsEl = this.tabsElRef.current;
|
|
2362
|
+
if (!tabsEl) {
|
|
2363
|
+
return false;
|
|
2364
|
+
}
|
|
2365
|
+
const hasTab = Array.from(tabsEl.querySelectorAll('ion-tab')).some((tabEl) => tabEl.tab === tab);
|
|
2366
|
+
if (!hasTab) {
|
|
2367
|
+
return false;
|
|
2368
|
+
}
|
|
2369
|
+
tabsEl.select(tab);
|
|
2370
|
+
return true;
|
|
2371
|
+
};
|
|
2372
|
+
onTabsDidChangeWithoutRouter = (event) => {
|
|
2373
|
+
this.ionTabContextState.activeTab = event.detail.tab;
|
|
2374
|
+
this.props.onIonTabsDidChange?.(event);
|
|
2375
|
+
};
|
|
2350
2376
|
renderTabsInner(children, outlet) {
|
|
2351
2377
|
return (jsx(IonTabsInner, { ...this.props, children: React.Children.map(children, (child) => {
|
|
2352
2378
|
if (React.isValidElement(child)) {
|
|
@@ -2422,7 +2448,14 @@ class IonTabs extends React.Component {
|
|
|
2422
2448
|
throw new Error('IonTabs cannot contain an IonRouterOutlet and an IonTab at the same time');
|
|
2423
2449
|
}
|
|
2424
2450
|
if (hasTab) {
|
|
2425
|
-
|
|
2451
|
+
/**
|
|
2452
|
+
* Core `ion-tabs` switches tabs and emits the tab change events
|
|
2453
|
+
* itself, so the tab bar gets no change handlers. Otherwise they
|
|
2454
|
+
* would run a second time from the tab bar's click handler.
|
|
2455
|
+
*/
|
|
2456
|
+
this.ionTabContextState.tabBarProps = { ref: this.tabBarRef };
|
|
2457
|
+
this.ionTabContextState.selectTab = this.selectTabWithoutRouter;
|
|
2458
|
+
return (jsx(IonTabsContext.Provider, { value: this.ionTabContextState, children: jsx(IonTabsInner, { ...this.props, ref: this.tabsElRef, onIonTabsDidChange: this.onTabsDidChangeWithoutRouter }) }));
|
|
2426
2459
|
}
|
|
2427
2460
|
/**
|
|
2428
2461
|
* TODO(ROU-11051)
|