Skip to content

[Tabs] Ink bar is not correctly aligned on init #3048

Closed

Description

@VitalyVrublevskyy

Bug, feature request, or proposal:

Bug (Some different than #3044)

What is the expected behavior?

Highlighter [md-ink-bar] should invalidate position on init app

What is the current behavior?

Misaligned [md-ink-bar]. Please see attached image.

What are the steps to reproduce?

Case 1

  1. Open demo application from material2
  2. Navigate to tabs (Especially for Tab Nav Bar with routing example)
  3. Apply md-stretch-tabs directive for and apply styles for tab items
    [md-stretch-tabs] [md-tab-link] { flex-basis: 0; flex-grow: 1; }
  4. Try to expand / collapse application sidebar.

Case 2 (or just apply attached git patch. )

  1. Open demo application from material2
  2. Setup <md-sidenav mode="side" opened="true"> for root app container.
  3. Navigate to tabs (Especially for Tab Nav Bar with routing example)
  4. Apply md-stretch-tabs directive for and apply styles for tab items
    [md-stretch-tabs] [md-tab-link] { flex-basis: 0; flex-grow: 1; }
  5. Select not first tab
  6. Refresh page

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Patch: MD_TabBar_issue.patch.zip

Which versions of Angular, Material, OS, browsers are affected?

Based on up to date sources of material2

Is there anything else we should know?

image

Activity

  1. added
    P3
    on Apr 9, 2017
  2. jarekskuder commented on Jul 24, 2017

    @jarekskuder

    Same here on iOS 10.3.2 cordova app

  3. changed the title [-]Misalignment of [md-ink-bar] element for Stretched Tabs on init app [/-] [+][Tabs] Ink bar is not correctly aligned on init[/+] on Oct 19, 2017
  4. levz0r commented on Feb 17, 2019

    @levz0r

    Hi,
    Any plans to fix this?

  5. Anderman commented on Mar 15, 2019

    @Anderman

    Is there a workarond for this?

  6. Anderman commented on Mar 16, 2019

    @Anderman

    I have this workarond

      @ViewChild(MatTabNav) public matTabNav: MatTabNav;
      public ngAfterViewChecked(): void {
        setTimeout(() => this.matTabNav._alignInkBar(), 0);
      }
  7. bentaly commented on Sep 30, 2019

    @bentaly

    This has changed to _alignInkBarToSelectedTab in Angular 8

  8. dhair-seva commented on Nov 2, 2019

    @dhair-seva

    This is happening to me, because my sidebar for the entire app has a width change on route change, so if I have a mat-tab-group in any page, I would have to implement this, which means, I would have to do this in over 10+ pages. This workaround is not a good fix for my use-case. Is there another fix, globally?

  9. omaracrystal commented on Sep 10, 2020

    @omaracrystal

    I also have ran into this issue. The mat-ink-bar does not recalculate when there is a material side nav with the mode set to "side". Here is my work around with css (I am hiding the mat-ink-bar and using &:after styling):

    • (add this to your global styles so it takes effect throughout your app)
    .mat-tab-label-active {
        .mat-tab-label-content {
          font-weight: bold;
          color: black;
    
          &:after {
            content: '';
            display: block;
            position: absolute;
            width: 100%;
            height: 2px;
            background: $blue-3;
            right: 0;
            bottom: 0;
          }
       }
    }
    
    mat-ink-bar {
      display: none !important;
    }
    
  10. IgorKurkov commented on Nov 23, 2020

    @IgorKurkov

    So it does not work till now.
    Workaround by @Anderman with ngAfterViewChecked() works but might cause performance problems.
    In my case content loads, and causes a vertical scrollbar, it resizes the page a bit (but window.onresize doesn't catch this resize event, so can't catch it yet), and sets the wrong alignment to mat-ink. My workaround - listen for routing event, wait for content loading by setTimeout with 1sec delay and realign mat-ink. But it is awful :) wait for a better neat solution

    @ViewChild('matTabsRef', { static: false }) matTabsRef: MatTabNav;
    
    fixResizeInkBar() {
      setTimeout(() => {
          if (this.matTabsRef) {
            this.matTabsRef._alignInkBarToSelectedTab();
          }
        }, 1000);
    }
    
    private listenRoutes(): void {
        this.subs.add(
          this.router.events
            .pipe(
              filter((event) => event instanceof NavigationEnd),
              startWith(true)
            )
            .subscribe((event) => {
              this.fixResizeInkBar();
            })
        );
      }
    
  11. simeyla commented on Sep 3, 2021

    @simeyla

    This can be even worse if the control is not visible on init.
    That ends up giving you width: 0px for the ink bar making it look like it just isn't working at all.

    For some cases the following can be a temporary fix.

    nav.mat-tab-nav-bar 
    {
        ::ng-deep .mat-ink-bar
        {
            min-width: 160px;
        }
    }
    

    Note: I'm using mat-tab-nav-bar as opposed to mat-tab-group but they use the same underlying ink bar.

  12. Melf11 commented on Feb 11, 2022

    @Melf11

    the mat-ripple-element ist causing this issue. I don't know what the mat-ripple-element is doing exactly, but for me it's not necessary, so do:

    .mat-ripple-element {
      display: none !important;
    }
    

    or

    <mat-tab-group [disableRipple]="true">
    
  13. angular-automatic-lock-bot commented on Jun 18, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: material/tabs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions