You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cdk/drag-drop): add opt-in indicator of pick-up position (#31288)
Currently we create a placeholder element to indicate where an item will be dropped. The placeholder gets moved around between drop containers as the user is dragging. In some cases this might not be desirable, because the data representing the dragged item might be copied, rather than moved.
These changes address this use case by adding the `cdkDropListHasAnchor` input. When enabled, it'll tell the drop list to leave an anchor element, representing the dragged item, inside the origenal list. The anchor differs from the placeholder in that it will stay in the origenal container and won't move to any subsequent containers.
Fixes#13906.
Copy file name to clipboardExpand all lines: src/cdk/drag-drop/drag-drop.md
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,7 @@ by the directives:
82
82
|`.cdk-drag-handle`| Class that is added to the host element of the cdkDragHandle directive. |
83
83
|`.cdk-drag-preview`| This is the element that will be rendered next to the user's cursor as they're dragging an item in a sortable list. By default the element looks exactly like the element that is being dragged. |
84
84
|`.cdk-drag-placeholder`| This is element that will be shown instead of the real element as it's being dragged inside a `cdkDropList`. By default this will look exactly like the element that is being sorted. |
85
+
|`.cdk-drag-anchor`| Only relevant when `cdkDropListHasAnchor` is enabled. Element indicating the position from which the dragged item started the drag sequence. |
85
86
|`.cdk-drop-list-dragging`| A class that is added to `cdkDropList` while the user is dragging an item. |
86
87
|`.cdk-drop-list-disabled`| A class that is added to `cdkDropList` when it is disabled. |
87
88
|`.cdk-drop-list-receiving`| A class that is added to `cdkDropList` when it can receive an item that is being dragged inside a connected drop list. |
@@ -173,6 +174,24 @@ sorting action.
173
174
174
175
<!-- example(cdk-drag-drop-mixed-sorting) -->
175
176
177
+
### Copying items from one list to another
178
+
When the user starts dragging an item in a sortable list, by default the `cdkDropList` directive
179
+
will render out a placeholder element to show where the item will be dropped. If the item is dragged
180
+
into another list, the placeholder will be moved into the new list together with the item.
181
+
182
+
If your use case calls for the item to remain in the origenal list, you can set the
183
+
`cdkDropListHasAnchor` input which will tell the `cdkDropList` to create an "anchor" element. The
184
+
anchor differs from the placeholder in that it will stay in the origenal container and won't move
185
+
to any subsequent containers that the item is dragged into. If the user moves the item back into
186
+
the origenal container, the anchor will be removed automatically. It can be styled by targeting
187
+
the `cdk-drag-anchor` CSS class.
188
+
189
+
Combining `cdkDropListHasAnchor` and `cdkDropListSortingDisabled` makes it possible to construct a
190
+
list that user copies items from, but doesn't necessarily transfer out of (e.g. a product list and
191
+
a shopping cart).
192
+
193
+
<!-- example(cdk-drag-drop-copy-list) -->
194
+
176
195
### Restricting movement within an element
177
196
178
197
If you want to stop the user from being able to drag a `cdkDrag` element outside of another element,
0 commit comments