-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(drag-drop): add docs and live examples #12794
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
Conversation
f99a068
to
b244465
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some text revision suggestions for grammar, passive voice, and brevity.
src/cdk/drag-drop/drag-drop.md
Outdated
@@ -1 +1,127 @@ | |||
# TODO | |||
The `@angular/cdk/drag-drop` module provides you with a way to easily and declaratively create | |||
drag&drop interfaces, with support for free dragging, sorting within a list, transferring items |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, fun grammar rules around "drag and drop":
- When used as an adjective, it should be hyphenated:
...the drag-and-drop features...
- When describing an action, it's not hyphenated:
...allows you to drag and drop...
src/cdk/drag-drop/drag-drop.md
Outdated
in addition to horizontal lists and locking along an axis. | ||
|
||
### Getting started | ||
To get started, you have to include the `DragDropModule` in your app's imports and add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start by importing `DragDropModule` into the `NgModule` where you want to use drag-and-drop
features. You can now add the `cdkDrag` directive to elements to make them draggable. When
outside of a `<cdk-drop>` element, draggable elements can be freely moved around the page.
You can add `<cdk-drop>` elements to constrain where elements may be dropped.
src/cdk/drag-drop/drag-drop.md
Outdated
|
||
<!-- example(cdk-drag-drop-overview) --> | ||
|
||
### Sorting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting -> Reordering lists
src/cdk/drag-drop/drag-drop.md
Outdated
as the user is dragging. Note that the CDK won't change the data for you, which means that you'll | ||
have to listen for the `dropped` event and re-arrange the date yourself once the user is done | ||
dragging. There are some provided utilities like the `moveItemInArray` and `transferArrayItem` | ||
functions that make it easier to manipulate your data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding `<cdk-drop>` around a set of `cdkDrag` elements groups the draggables into a
reorderable collection. Items will automatically rearrange as an element moves. Note
that this will *not* update your data model; you can listen to the `dropped` event to
update the data model once the user finishes dragging.
I'm wondering if we should expose the moveItemInArray
and transferArrayItem
functions publicly. I worry that people will start to think that it's the only way to update their model, and then start filing issues requesting things like handling async updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean, but hopefully people will realize that they're just dealing with arrays. I added the functions since some things like move an item inside an array aren't trivial one-liners.
src/cdk/drag-drop/drag-drop.md
Outdated
|
||
<!-- example(cdk-drag-drop-sorting) --> | ||
|
||
### Sorting between lists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Sorting between lists" -> "Transferring items between lists"
src/cdk/drag-drop/drag-drop.md
Outdated
* `.cdk-drag-placeholder` - This is element that will be shown instead of the real element as it's | ||
being dragged inside a `cdk-drop`. By default this will look exactly like the element that is | ||
being sorted. | ||
* `.cdk-drop-dragging` - A class that is added to `cdk-drop` while the user is dragging an item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably be good as a table
src/cdk/drag-drop/drag-drop.md
Outdated
<!-- example(cdk-drag-drop-handle) --> | ||
|
||
### Customizing the preview element | ||
By default, when the user starts dragging an item inside a sortable list, the CDK will create a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would omit the css class here since it's mentioned above.
When a `cdkDrag` element is picked up, it will create a preview element visible while dragging.
By default, this will be a clone of the original element positioned next to the user's cursor.
This preview can be customized, though, by providing a custom template via `*cdkDragPreview`:
src/cdk/drag-drop/drag-drop.md
Outdated
|
||
<!-- example(cdk-drag-drop-handle) --> | ||
|
||
### Customizing the preview element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Customizing the drag preview"
src/cdk/drag-drop/drag-drop.md
Outdated
|
||
### List orientation | ||
The `cdk-drop` component defaults to sorting lists vertically, however you can make a list that is | ||
sorted horizontally by setting the `orientation` input to `horizontal`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `cdk-drop` component assumes that lists are vertical by default. This can be
changed by setting the `orientation` property to `"horizontal".
src/cdk/drag-drop/drag-drop.md
Outdated
<!-- example(cdk-drag-drop-horizontal-sorting) --> | ||
|
||
### Restricting movement along an axis | ||
By default, the CDK allows the user to move the drag preview around freely in both the X and Y axis, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, `cdkDrag` allows free movement in all directions. To restrict dragging to a
specific axis, you can set `cdkDragLockAxis` on `cdkDrag` or `lockAxis` on `<cdk-drop>`
to either `"x"` or `"y"`.
Adds live examples and a readme for the CDK drag&drop.
b244465
to
ba0742d
Compare
I've incorporated the feedback @jelbourn. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
Adds live examples and a readme for the CDK drag&drop.