Support re-ordering tabs via cdk drag-drop

See original GitHub issue

Not sure if this would be doing some work in cdk/drag-drop that will make it automatically work on the tabs, or if a supplemental directive would be necessary.

Some of my thoughts:

  • Tabs on its own can’t have a dependency on cdk/drag-drop
  • Will have to take tab pagination into account, probably autoscrolling
  • Need to decide whether the tabs move as you drag or if it only shows an indicator for where the tab will drop

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:20
  • Comments:23 (7 by maintainers)

github_iconTop GitHub Comments

11reactions
dwightnaylorcommented, May 22, 2019

Are there are updates wrt documentation for this?

10reactions
MiguelRozalencommented, Dec 21, 2018

I managed it with 7.2 using CDK library:

<mat-tab-group style="position: absolute; background-color: aqua;top: 0;">
  <mat-tab *ngFor="let view of views; let i = index">
    <ng-template mat-tab-label>
      <div [id]="'list-'+i" class="drag-list" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="drop($event)" [cdkDropListConnectedTo]="getAllListConnections(index)">
        <div class="drag-box" cdkDrag>{{view}}</div>
      </div>
    </ng-template>
    Content {{view}}
  </mat-tab>
</mat-tab-group>
 getAllListConnections(index){
    var connections = []
    for(var i=0;i<views.length;i++){
      if(i!=index){
        connections.push("list-"+i);
      }
    }
    return connections;
  }

Then in th event handler you have to manage the order of mat-tabs, like:

drop(event: CdkDragDrop<string[]>) {
    var previousIndex = parseInt(event.previousContainer.id.replace("list-",""));
    var currentIndex = parseInt(event.container.id.replace("list-",""));
    if(previousIndex!=NaN && currentIndex!=NaN && previousIndex!=undefined && currentIndex!=undefined && previousIndex!=currentIndex){
         //Do stuff
        .....
        //END Stuff
        moveItemInArray(this.views, previousIndex, currentIndex);
    }
}

Hope it helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Drag and Drop
Adding cdkDropList around a set of cdkDrag elements groups the draggables into a reorderable collection. Items will automatically rearrange as an element moves....
Read more >
Make Angular Material tabs drag/drop re-order tab index
Is there any way to make Angular Material tabs drag/drop, re-order the tab index using: CDK drag-drop service. CDK Drag-Drop - Service.
Read more >
Reordering tabs with drag and drop
I was wondering if anyone has had success using either rich:tabpanel or rich:togglepanel which give the end users the ability to reorder the ......
Read more >
Getting to Know the Angular CDK Drag and Drop Feature
In this article, we'll learn how to use the drag and drop feature. ... The cdk-drop component supports transferring dragged items between connected...
Read more >
Exploring Drag and Drop with the new Angular Material CDK
Now that we know how to create a draggable item and a drop zone, the next step is to drag and re-order items...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found