@ionic/react 9.0.14-nightly.20261125 → 9.0.15-dev.11796226497.1324df76

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
- if (this.tabBarRef.current) {
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,31 @@ 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
+ /**
2374
+ * A tab change without a router does not re-render anything, so the
2375
+ * context needs a new value and a re-render to update its consumers.
2376
+ */
2377
+ this.ionTabContextState = { ...this.ionTabContextState, activeTab: event.detail.tab };
2378
+ this.forceUpdate();
2379
+ this.props.onIonTabsDidChange?.(event);
2380
+ };
2350
2381
  renderTabsInner(children, outlet) {
2351
2382
  return (jsx(IonTabsInner, { ...this.props, children: React.Children.map(children, (child) => {
2352
2383
  if (React.isValidElement(child)) {
@@ -2422,7 +2453,14 @@ class IonTabs extends React.Component {
2422
2453
  throw new Error('IonTabs cannot contain an IonRouterOutlet and an IonTab at the same time');
2423
2454
  }
2424
2455
  if (hasTab) {
2425
- return jsx(IonTabsInner, { ...this.props });
2456
+ /**
2457
+ * Core `ion-tabs` switches tabs and emits the tab change events
2458
+ * itself, so the tab bar gets no change handlers. Otherwise they
2459
+ * would run a second time from the tab bar's click handler.
2460
+ */
2461
+ this.ionTabContextState.tabBarProps = { ref: this.tabBarRef };
2462
+ this.ionTabContextState.selectTab = this.selectTabWithoutRouter;
2463
+ return (jsx(IonTabsContext.Provider, { value: this.ionTabContextState, children: jsx(IonTabsInner, { ...this.props, ref: this.tabsElRef, onIonTabsDidChange: this.onTabsDidChangeWithoutRouter, children: children }) }));
2426
2464
  }
2427
2465
  /**
2428
2466
  * TODO(ROU-11051)
@@ -3157,6 +3195,7 @@ const RouteManagerContext = /*@__PURE__*/ React.createContext({
3157
3195
  findViewItemByRouteInfo: () => undefined,
3158
3196
  getChildrenToRender: () => undefined,
3159
3197
  getViewItemsForOutlet: () => [],
3198
+ getLocationHistoryPathnames: () => [],
3160
3199
  goBack: () => undefined,
3161
3200
  unMountViewItem: () => undefined,
3162
3201
  });
@@ -3357,6 +3396,13 @@ class LocationHistory {
3357
3396
  canGoBack() {
3358
3397
  return this.locationHistory.length > 1;
3359
3398
  }
3399
+ /**
3400
+ * Returns the pathname of every entry in global history, oldest first.
3401
+ * The current entry is last.
3402
+ */
3403
+ getPathnames() {
3404
+ return this.locationHistory.map((ri) => ri.pathname);
3405
+ }
3360
3406
  findTabForPathname(pathname) {
3361
3407
  for (const tab of Object.keys(this.tabHistory)) {
3362
3408
  const routeInfos = this.tabHistory[tab];