forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(drag-drop): add the ability to disable dragging
Adds inputs to `cdkDrag`, `cdkDropList` and `cdkDragHandle` that allows for dragging to be disabled through those specific elements. Fixes angular#13651.
- Loading branch information
Showing
9 changed files
with
184 additions
and
4 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
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
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
48 changes: 48 additions & 0 deletions
48
src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-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,48 @@ | ||
.example-list { | ||
width: 500px; | ||
max-width: 100%; | ||
border: solid 1px #ccc; | ||
min-height: 60px; | ||
display: block; | ||
background: white; | ||
border-radius: 4px; | ||
overflow: hidden; | ||
} | ||
|
||
.example-box { | ||
padding: 20px 10px; | ||
border-bottom: solid 1px #ccc; | ||
color: rgba(0, 0, 0, 0.87); | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
box-sizing: border-box; | ||
cursor: move; | ||
background: white; | ||
font-size: 14px; | ||
} | ||
|
||
.cdk-drag-preview { | ||
box-sizing: border-box; | ||
border-radius: 4px; | ||
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), | ||
0 8px 10px 1px rgba(0, 0, 0, 0.14), | ||
0 3px 14px 2px rgba(0, 0, 0, 0.12); | ||
} | ||
|
||
.cdk-drag-placeholder { | ||
opacity: 0; | ||
} | ||
|
||
.cdk-drag-animating { | ||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); | ||
} | ||
|
||
.example-box:last-child { | ||
border: none; | ||
} | ||
|
||
.example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) { | ||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-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,7 @@ | ||
<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)"> | ||
<div | ||
class="example-box" | ||
*ngFor="let item of items" | ||
cdkDrag | ||
[cdkDragDisabled]="item.disabled">{{item.value}}</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-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,22 @@ | ||
import {Component} from '@angular/core'; | ||
import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop'; | ||
|
||
/** | ||
* @title Drag&Drop disabled | ||
*/ | ||
@Component({ | ||
selector: 'cdk-drag-drop-disabled-example', | ||
templateUrl: 'cdk-drag-drop-disabled-example.html', | ||
styleUrls: ['cdk-drag-drop-disabled-example.css'], | ||
}) | ||
export class CdkDragDropDisabledExample { | ||
items = [ | ||
{value: 'I can be dragged', disabled: false}, | ||
{value: 'I cannot be dragged', disabled: true}, | ||
{value: 'I can also be dragged', disabled: false} | ||
]; | ||
|
||
drop(event: CdkDragDrop<string[]>) { | ||
moveItemInArray(this.items, event.previousIndex, event.currentIndex); | ||
} | ||
} |