-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e739271
correctly blocking onClick for all element types
alexreardon 43cca2e
adding comments
alexreardon 592c7e1
updating naming and readme
alexreardon b84b1ce
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon 34eb41b
improving readme
alexreardon 99fcaab
fixing comment
alexreardon 8cded9b
mouse wheel scrolling is back
alexreardon 1301969
tightening up structure
alexreardon b130396
simplifying and adding mobile support
alexreardon 71c6e70
cleanup of types
alexreardon b8ebf3e
updating tests
alexreardon 7cb55fe
updating readme
alexreardon f288e54
readme fix
alexreardon 4dbdd94
reverting get style changes
alexreardon 342501b
moving content around
alexreardon fcf4e5d
correcting DragHandleProps type in readme
alexreardon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
```css | ||
cursor: grabbing; | ||
``` | ||
|
||
This is what we use to control `Draggable`s that need to move out of the way of a dragging `Draggable`. | ||
|
||
```css | ||
|
@@ -378,7 +384,7 @@ This is described by the type [`DraggableStyle`](https://github.com/atlassian/re | |
|
||
#### (Phase: dragging): body element | ||
|
||
We apply a cursor while dragging to give user feedback that a drag is occurring. You are welcome to override this. A good point to do this is the `onDragStart` event. | ||
We apply a cursor while dragging to give user feedback that a drag is occurring. You are welcome to override this. A good point to do this is the `onDragStart` event. This style is applied on both the `drag handle` as well as the `body`. We apply it to the `body` in case the user pointer *slips* off the `drag handle` during a drag. This is possible as we throttle movements into request animation frames. | ||
|
||
```css | ||
cursor: grabbing; | ||
|
@@ -959,7 +965,6 @@ export type DraggableProps = {| | |
|
||
type DraggableStyle = DraggingStyle | NotDraggingStyle | ||
type DraggingStyle = {| | ||
pointerEvents: 'none', | ||
position: 'fixed', | ||
width: number, | ||
height: number, | ||
|
@@ -1091,7 +1096,6 @@ It is an assumption that `Draggable`s are *visible siblings* of one another. The | |
type DragHandleProps = {| | ||
onMouseDown: (event: MouseEvent) => void, | ||
onKeyDown: (event: KeyboardEvent) => void, | ||
onClick: (event: MouseEvent) => void, | ||
tabIndex: number, | ||
'aria-grabbed': boolean, | ||
draggable: boolean, | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer using 'click' as part of the example |
||
|
||
<Draggable draggableId="draggable-1" index={0}> | ||
{(provided, snapshot) => { | ||
const onClick = (() => { | ||
const onMouseDown = (() => { | ||
// dragHandleProps might be null | ||
if (!provided.dragHandleProps) { | ||
return myOnClick; | ||
return onMouseDown; | ||
} | ||
|
||
// creating a new onClick function that calls my onClick | ||
// event as well as the provided one. | ||
return event => { | ||
provided.dragHandleProps.onClick(event); | ||
// You may want to check if event.defaultPrevented | ||
// is true and optionally fire your handler | ||
myOnClick(event); | ||
// creating a new onMouseDown function that calls myOnMouseDown as well as the drag handle one. | ||
return (event) => { | ||
provided.dragHandleProps.onMouseDown(event); | ||
myOnMouseDown(event); | ||
}; | ||
})(); | ||
|
||
|
@@ -1168,7 +1169,7 @@ const myOnClick = event => console.log('clicked on', event.target); | |
ref={provided.innerRef} | ||
{...provided.draggableProps} | ||
{...provided.dragHandleProps} | ||
onClick={onClick} | ||
onMouseDown={onMouseDown} | ||
> | ||
Drag me! | ||
</div> | ||
|
@@ -1335,7 +1336,6 @@ export type DraggableProps = {| | |
|} | ||
type DraggableStyle = DraggingStyle | NotDraggingStyle | ||
type DraggingStyle = {| | ||
pointerEvents: 'none', | ||
position: 'fixed', | ||
width: number, | ||
height: number, | ||
|
@@ -1352,18 +1352,16 @@ type NotDraggingStyle = {| | |
transition: ?string, | ||
transition: null | 'none', | ||
|} | ||
type DragHandleProvided = {| | ||
|
||
type DragHandleProps = {| | ||
onMouseDown: (event: MouseEvent) => void, | ||
onKeyDown: (event: KeyboardEvent) => void, | ||
onClick: (event: MouseEvent) => void, | ||
onTouchStart: (event: TouchEvent) => void, | ||
onTouchMove: (event: TouchEvent) => void, | ||
tabIndex: number, | ||
'aria-roledescription': string, | ||
'aria-grabbed': boolean, | ||
draggable: boolean, | ||
onDragStart: () => boolean, | ||
onDrop: () => boolean | ||
|} | ||
onDragStart: () => void, | ||
onDrop: () => void, | ||
|}; | ||
``` | ||
|
||
### Using the flow types | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
// @flow | ||
import type { Props, Callbacks } from '../drag-handle-types'; | ||
|
||
export type Sensor = { | ||
type SensorBase = {| | ||
// force stop and do not fire any events | ||
kill: () => void, | ||
// Is the sensor currently recording a drag | ||
isDragging: () => boolean, | ||
// Is the sensor listening for events. | ||
// This can happen before a drag starts | ||
isCapturing: () => boolean, | ||
} | ||
|} | ||
|
||
export type CreateSensorArgs = {| | ||
callbacks: Callbacks, | ||
getDraggableRef: () => ?HTMLElement, | ||
canStartCapturing: (event: Event) => boolean, | ||
|} | ||
|
||
export type MouseSensor = Sensor & { | ||
export type MouseSensor = {| | ||
...SensorBase, | ||
onMouseDown: (event: MouseEvent) => void, | ||
onClick: (event: MouseEvent) => void, | ||
} | ||
|} | ||
|
||
export type KeyboardSensor = Sensor & { | ||
export type KeyboardSensor = {| | ||
...SensorBase, | ||
onKeyDown: (event: KeyboardEvent, props: Props) => void, | ||
} | ||
|} | ||
|
||
export type TouchSensor = Sensor & { | ||
export type TouchSensor = {| | ||
...SensorBase, | ||
onTouchStart: (event: TouchEvent) => void, | ||
onTouchMove: (event: TouchEvent) => void, | ||
onClick: (event: MouseEvent) => void, | ||
} | ||
|} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 need to remove these new comments (they are no longer needed)