-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(cdk/drag-drop): add tabs example (#29517)
Adds an example that shows how to add drag&drop support to a `mat-tab-group`. Fixes #13572.
- Loading branch information
Showing
6 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/components-examples/cdk/drag-drop/cdk-drag-drop-tabs/cdk-drag-drop-tabs-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.example-drag-tabs.cdk-drop-list-dragging { | ||
pointer-events: none; | ||
} | ||
|
||
.example-drag-tabs-preview.cdk-drag-animating { | ||
transition: all 250ms cubic-bezier(0, 0, 0.2, 1); | ||
} | ||
|
||
.mat-mdc-tab.example-drag-tabs-preview { | ||
outline: dashed 1px #ccc; | ||
outline-offset: 4px; | ||
} | ||
|
||
.example-drag-tabs .cdk-drag-placeholder { | ||
opacity: 0.5; | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
src/components-examples/cdk/drag-drop/cdk-drag-drop-tabs/cdk-drag-drop-tabs-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<mat-tab-group | ||
cdkDropList | ||
cdkDropListOrientation="horizontal" | ||
(cdkDropListDropped)="drop($event)" | ||
cdkDropListElementContainer=".mat-mdc-tab-labels" | ||
class="example-drag-tabs" | ||
[(selectedIndex)]="selectedTabIndex" | ||
animationDuration="0"> | ||
@for (tab of tabs; track $index) { | ||
<mat-tab> | ||
<ng-template mat-tab-label> | ||
<span | ||
cdkDrag | ||
cdkDragPreviewClass="example-drag-tabs-preview" | ||
cdkDragRootElement=".mat-mdc-tab">{{tab}}</span> | ||
</ng-template> | ||
|
||
<h3>Content for {{tab}}</h3> | ||
|
||
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quidem perspiciatis in delectus | ||
reprehenderit, molestias ullam nostrum odit, modi consequatur harum beatae? Sapiente | ||
voluptatibus illo natus assumenda hic quasi dolor et laborum veniam! Molestiae architecto | ||
nesciunt est quo nisi? Nostrum repellendus quibusdam laudantium? Optio architecto explicabo | ||
labore sapiente cum alias nobis! | ||
</mat-tab> | ||
} | ||
</mat-tab-group> |
25 changes: 25 additions & 0 deletions
25
src/components-examples/cdk/drag-drop/cdk-drag-drop-tabs/cdk-drag-drop-tabs-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {Component, ViewEncapsulation} from '@angular/core'; | ||
import {CdkDrag, CdkDragDrop, CdkDropList, moveItemInArray} from '@angular/cdk/drag-drop'; | ||
import {MatTabsModule} from '@angular/material/tabs'; | ||
|
||
/** | ||
* @title Drag&Drop tabs | ||
*/ | ||
@Component({ | ||
selector: 'cdk-drag-drop-tabs-example', | ||
templateUrl: 'cdk-drag-drop-tabs-example.html', | ||
styleUrl: 'cdk-drag-drop-tabs-example.css', | ||
standalone: true, | ||
imports: [CdkDrag, CdkDropList, MatTabsModule], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class CdkDragDropTabsExample { | ||
protected tabs = ['One', 'Two', 'Three', 'Four', 'Five']; | ||
protected selectedTabIndex = 0; | ||
|
||
drop(event: CdkDragDrop<string[]>) { | ||
const prevActive = this.tabs[this.selectedTabIndex]; | ||
moveItemInArray(this.tabs, event.previousIndex, event.currentIndex); | ||
this.selectedTabIndex = this.tabs.indexOf(prevActive); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters