Skip to content

[Tabs] Slide animation for mat-tab-nav-bar (Continuation) #18169

Closed
@domvelo

Description

@domvelo

Continuation on a bot closed issue. Due to inactivity. #15570

@dflor003 @andrewseguin This is a router animation issue. You switched from a inline tab navigation to a tab router navigation. The tab content has nothing to do with the Angular Material tab content component. You have to implement route transition animations.

If possible, the Angular Material framework should implement this route transition animation for the mat-tab-nav-bar. Maybe it can be done by a wrapping component? Around the nav and the router-outlet. I'm currently experimenting a bit with tab routing. The next step is to bring back the animations. I have no working demo yet...

Currently I have only a solution to store router data for the tab index and animate inrement or decrement with slide left or right. Some snippets:

export const tabAnimation = trigger('tabAnimation', [
  transition(':increment', slideRight),
  transition(':decrement', slideLeft)
]);
const routes: Routes = [
      {
        path: 'some-route',
        component: SomeComponent,
        data: { index: 1 }
      },
      {
        path: 'another-route',
        component: AnotherComponent,
        data: { index: 2 }
      },
];
  public getRouterOutletState(outlet: RouterOutlet) {
    return outlet.activatedRouteData === undefined ? -1 : outlet.activatedRouteData.index;
  }
<main [@tabAnimation]="getRouterOutletState(o)">
  <router-outlet #o="outlet"></router-outlet>
</main>

(main or div or whatever.)

Google for "angular router tabs animation". Find e.g. this on stackoverflow

It works. But I'm sure there is a more elegant way. For example: How to get the tab index automatically. Without set custom router data. ... Maybe there is a way to pass the router data dynamically with the tab index. Or you just use one animation for both direction. Because the router data is only required if you want to decide you to slide. Left or right. Or just generate the router entries by a function and automatically add the index to the data.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions