Skip to content
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

correctly blocking onClick for all element types #353

Merged
merged 16 commits into from
Feb 28, 2018

Conversation

alexreardon
Copy link
Collaborator

Fixes #273.

This is required for #10.

onClick event handlers are not firing on the drag handle because it has pointer-events: none; applied to it. This means that it fires on the parent. Confusingly the onClick handler will fire on the element if the element is an anchor. There is a work around (see #10) but it is hacky. This change would make onClick fire correctly on the drag handle every time. It involves removing pointer-events: none off the dragging drag handle. This has no performance implications.

There is a drawback. By changing this you will no longer be able to use the mouse wheel to scroll a Droppable underneath a dragging item. Disabling pointer events allowed the user to 'scroll through' the dragging item. Turning them back on means that they can no longer do this. However, I think given that users can now automatically scroll the window and scroll containers by using mouse movement this is acceptable. I have investigated the other drag and drop libraries out there that I could and they all have this restriction.

I think on the whole this is a positive and useful change as it delivers more thoroughly on our attempt to correctly block click events

@@ -113,8 +114,8 @@ export default (styleContext: string): Styles => {
// > Applied while the user is actively dragging

// cursor: grab
// We apply this by default for an improved user experience. It is such a common default that we
// bake it right in. Consumers can opt out of this by adding a selector with higher specificity
// We apply apply this style to the body in case the user pointer
Copy link
Contributor

Choose a reason for hiding this comment

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

absolute nitpick but you've written 'apply' here twice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'll fix it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@alexreardon
Copy link
Collaborator Author

It sucks we need to do this - but it is for the best

@alexreardon
Copy link
Collaborator Author

I was not happy to loose wheel scrolling so I have changed how we do post drag click prevention. It is working really well.

@alexreardon
Copy link
Collaborator Author

alexreardon commented Feb 28, 2018

A point for discussion is whether this should be a breaking change. I have currently removed onClick from DragHandleProps which is a breaking change. I add it back in and make it a no-opt to make this a non breaking change. However, doing this means that future consumers need to monkey patch onClick for no reason until we do the next major release (which sucks). Also, we are techinically changing the behaviour of the onClick function. Before if it was an anchor it would be called every time regardless of whether we performed click blocking or not. Now it will not be called at all if we are blocking the click. I think this change of behaviour gives further weight to the idea that this should be labeled as a breaking change.

Thoughts @jaredcrowe @Blasz ?

My personal thought is to keep the api as tight as possible and drop onClick and move to 6.0.

README.md Outdated
@@ -366,6 +366,12 @@ point-events: none;

**Styles applied using the `data-react-beautiful-dnd-draggable` attribute**

We apply a cursor while dragging to give user feedback that a drag is occurring. You are welcome to override this by applying your own cursor to the element with a greater specificity.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to remove these new comments (they are no longer needed)

@@ -1142,23 +1146,20 @@ Controlling a whole draggable by just a part of it
You can override some of the `dragHandleProps` props with your own behavior if you need to.

```js
const myOnClick = event => console.log('clicked on', event.target);
const myOnMouseDown = event => console.log('mouse down on', event.target);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no longer using 'click' as part of the example

@@ -65,9 +64,11 @@ export default (styleContext: string): Styles => {
cursor: grab;
}
`,
blockPointerEvents: `
whileActiveDragging: `
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be undone

@alexreardon
Copy link
Collaborator Author

I have tested this on our supported desktop browsers. I still need to test it on mobile (ios and andriod)

@alexreardon
Copy link
Collaborator Author

It is looking good on ios. I'll check andriod after lunch

@jaredcrowe
Copy link
Contributor

If it wasn't for the fact that anchors won't always get their onClick called now I would have said make DragHandleProps.onClick a no-op and remove it next major. But since that behaviour is changing I agree that we should probably make a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants