0
votes

I have created vertical tab using angular material and want to add Add Tab button, I can add that button but it's adding in the bottom. I want to add that button in vertical tab listing.

Here is stackblitz link which adds tab on click of button. Add Tab button should be in vertical tab.

html:

<mat-tab-group [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)">
  <mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
    Contents for {{tab}} tab
  </mat-tab>
</mat-tab-group>
<button mat-raised-button class="example-add-tab-button add-tab-btn" (click)="addTab()">  Add Tab </button>

TS:

import {Component} from '@angular/core';
import { FormControl} from '@angular/forms';

/**
 * @title Basic use of the tab group
 */
@Component({
  selector: 'tab-group-basic-example',
  templateUrl: 'tab-group-basic-example.html',
  styleUrls: ['tab-group-basic-example.css'],
})
export class TabGroupBasicExample {
  tabs = ['First', 'Second'];
  selected = new FormControl(0);
  selectAfterAdding: boolean;
  addTab() {
    this.selectAfterAdding = true;
    this.tabs.push('New');
    if(this.selectAfterAdding) {
      this.selected.setValue(this.tabs.length - 1);
    }
  }
}

How to add Add Tab button vertical tabs?

2

2 Answers

2
votes
<mat-tab-group [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)">

<mat-tab disabled>
                <ng-template mat-tab-label>
                    <button mat-icon-button (click)="addTab()">
                        <mat-icon>add_circle</mat-icon>
                    </button>
                </ng-template>
          </mat-tab>

  <mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
    Contents for {{tab}} tab
  </mat-tab>
</mat-tab-group> 

use this before or after your ng-for

0
votes

Your flex-direction is "column". You need to change this "column" to "row";

 .mat-tab-labels{ 
     flex-direction:row !important;
 }