-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support re-ordering tabs via cdk drag-drop #13572
Comments
If we want something that “just works”, we’ll need some kind of abstraction around the mat-tab-group since we don’t have access to the data that’s driving the tabs and the consumer doesn’t have direct access to the tab label itself. |
It doesn't necessarily have to work without the user doing anything extra, there just needs to be a supported (documented) way of doing it. |
I see. In that case we definitely need some kind of alternate API for the drag&drop that works with generated elements since the tabs work by taking the content, putting it in an |
Another thing that came up: dragging tabs between groups |
@crisbeto This is a very simple implementation without coupling https://stackblitz.com/edit/angular-mgrsxx-tfeye2?file=app/tab-group-basic-example.ts Notes:
|
Thanks a lot! Indeed our use case does involve moving tabs between tab groups, so will look forward to those two being resolved as well! |
@mtaran-google this use case is in most part supported... Here's a rough POC: https://stackblitz.com/edit/angular-mgrsxx-tzpqjc?file=app%2Ftab-group-basic-example.html Currently, there are 2 bugs I know of:
The 2nd issue also causes the drop area to be the entire Both issues have temp workaround via directives i've wrapped around Other than that all bugs and issues in this POC are solvable with some work on solid wrapper directives that know how to work with the tabs. Maybe some API is required to allow programmatic control over the tabs... Anyway, I think that each and every CDK components must come with an extensive API that allows complete programmatic control, this is a must. In angular, your end goal is to work with templates as much as possible, because more template -> less code -> fewer bugs. But this is true for apps, not for low level components, having extensive API in the low-level components will lead to applications with less code. |
I managed it with 7.2 using CDK library:
Then in th event handler you have to manage the order of mat-tabs, like:
Hope it helps |
This works nicely - many thanks. But curiously it seems to kill the isActive flag on the tabs. |
is there any progress? |
The necessary APIs for this were added in #14437, but we haven't gotten around to writing a guide for it yet. |
Are there are updates wrt documentation for this? |
@MiguelRozalen thanks, your solution works great ! |
Are there any updates regarding documentation for drag&drop mat tabs? |
Hi @MiguelRozalen can you maybe help me with your implementation Stackoverflow question , do you maybe have idea why this is not working ? |
Are there any updates regarding documentation for drag&drop mat tabs? |
+1 |
Any update on this? |
Found a working solution:
|
Hey! @AlvaroP95 can you please share stackblitz solution as this code is not working for me. |
I think Ivy don't listen to input changes. Is for that you need to force it. If you have an easy tabs object, you can use @AlvaroP95 solution. ... //here moveitem But if you have some map with key reference instead of ids, you need to update it to use the get method from the map. ... //here move item this.tabs.forEach((oldTab, index) => {
|
Hello guys I created a little demo for you if you have still this problem: |
Hello, it seems that auto-scroll is not working when dragging a tab. Is there a way to make it work? See: https://stackblitz.com/edit/angular-wpv2er-djgsig?file=src%2Fapp%2Fcdk-drag-drop-horizontal-sorting-example.ts,src%2Fapp%2Fcdk-drag-drop-horizontal-sorting-example.html Grab a tab and try to go left or right to make it scroll. Nothing is happening. |
A workaround that I used was to switch from the tabs component to Angular Material Button Toggle component. In my case, I had to use a right-click menu on the tabs as well as reorder, and both were giving me headaches with the tabs component. With the Button Toggle component, both the drag-to-reorder and the right-click menu just seamlessly work without any hacks. Here, I only share selected lines from my solution, I might have missed something but this is so simple, I am sure you guys can make it work in your code just by following the Angular Material docs. <mat-button-toggle-group
cdkDropList
(cdkDropListDropped)="onTabDragDrop($event)"
cdkDropListOrientation="horizontal"
>
<mat-button-toggle
*ngFor="let tab of tabs"
cdkDrag
>
{{ tab.label }}
</mat-button-toggle>
</mat-button-toggle-group> In the |
Adds an example that shows how to add drag&drop support to a `mat-tab-group`. Fixes angular#13572.
@PierreDugue I have the same exact auto-scroll challenge. Did you find a solution for that? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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:
cdk/drag-drop
The text was updated successfully, but these errors were encountered: