Skip to content

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

Merged
merged 1 commit into from
Aug 25, 2018

Conversation

crisbeto
Copy link
Member

Adds live examples and a readme for the CDK drag&drop.

@crisbeto crisbeto added docs This issue is related to documentation pr: merge safe target: major This PR is targeted for the next major release labels Aug 22, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 22, 2018
Copy link
Member

@jelbourn jelbourn left a 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.

@@ -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
Copy link
Member

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...

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
Copy link
Member

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.


<!-- example(cdk-drag-drop-overview) -->

### Sorting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting -> Reordering lists

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.
Copy link
Member

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.

Copy link
Member Author

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.


<!-- example(cdk-drag-drop-sorting) -->

### Sorting between lists
Copy link
Member

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"

* `.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.
Copy link
Member

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

<!-- 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
Copy link
Member

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`:


<!-- example(cdk-drag-drop-handle) -->

### Customizing the preview element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Customizing the drag preview"


### 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`:
Copy link
Member

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".

<!-- 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,
Copy link
Member

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.
@crisbeto
Copy link
Member Author

I've incorporated the feedback @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Aug 25, 2018
@ngbot
Copy link

ngbot bot commented Aug 25, 2018

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure status "continuous-integration/travis-ci/pr" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@jelbourn jelbourn merged commit c8ae9fd into angular:master Aug 25, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement docs This issue is related to documentation target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants