Skip to content

Commit fe56952

Browse files
crisbetommalerba
authored andcommitted
docs(drag-drop): add docs and live example for delay input (#15370)
Adds some docs and a live example for the `cdkDragStartDelay` input. Follow-up from #14732. **Note:** targeting `major`, because the PR that introduces the functionality was merged into the next major branch.
1 parent 472cccd commit fe56952

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/cdk/drag-drop/drag-drop.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ be allowed into the new container.
172172

173173
<!-- example(cdk-drag-drop-enter-predicate) -->
174174

175-
### Disable dragging
175+
### Disabled dragging
176176
If you want to disable dragging for a particular drag item, you can do so by setting the
177177
`cdkDragDisabled` input on a `cdkDrag` item. Furthermore, you can disable an entire list
178178
using the `cdkDropListDisabled` input on a `cdkDropList` or a particular handle via
@@ -188,3 +188,13 @@ in addition to preserving the dragged item's initial position in the source list
188188
decides to return the item.
189189

190190
<!-- example(cdk-drag-drop-disabled-sorting) -->
191+
192+
### Delayed dragging
193+
By default as soon as the user puts their pointer down on a `cdkDrag`, the dragging sequence will
194+
be started. This might not be desirable in cases like fullscreen draggable elements on touch
195+
devices where the user might accidentally trigger a drag as they're scrolling the page. For
196+
cases like these you can delay the dragging sequence using the `cdkDragStartDelay` input which
197+
will wait for the user to hold down their pointer for the specified number of milliseconds before
198+
moving the element.
199+
200+
<!-- example(cdk-drag-drop-delay) -->
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.example-box {
2+
width: 200px;
3+
height: 200px;
4+
border: solid 1px #ccc;
5+
color: rgba(0, 0, 0, 0.87);
6+
cursor: move;
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
text-align: center;
11+
background: #fff;
12+
border-radius: 4px;
13+
position: relative;
14+
z-index: 1;
15+
transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
16+
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
17+
0 2px 2px 0 rgba(0, 0, 0, 0.14),
18+
0 1px 5px 0 rgba(0, 0, 0, 0.12);
19+
}
20+
21+
.example-box:active {
22+
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
23+
0 8px 10px 1px rgba(0, 0, 0, 0.14),
24+
0 3px 14px 2px rgba(0, 0, 0, 0.12);
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="example-box" cdkDrag [cdkDragStartDelay]="1000">
2+
Dragging starts after one second
3+
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title Delayed dragging
5+
*/
6+
@Component({
7+
selector: 'cdk-drag-drop-delay-example',
8+
templateUrl: 'cdk-drag-drop-delay-example.html',
9+
styleUrls: ['cdk-drag-drop-delay-example.css'],
10+
})
11+
export class CdkDragDropDelayExample {}

0 commit comments

Comments
 (0)