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

Update Hook types to return mixed vs void (addresses #695) #704

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@ type Hooks = {|
onDragEnd: OnDragEndHook,
|};

type OnBeforeDragStartHook = (start: DragStart) => void;
type OnDragStartHook = (start: DragStart, provided: HookProvided) => void;
type OnDragUpdateHook = (update: DragUpdate, provided: HookProvided) => void;
type OnDragEndHook = (result: DropResult, provided: HookProvided) => void;
type OnBeforeDragStartHook = (start: DragStart) => mixed;
type OnDragStartHook = (start: DragStart, provided: HookProvided) => mixed;
type OnDragUpdateHook = (update: DragUpdate, provided: HookProvided) => mixed;
type OnDragEndHook = (result: DropResult, provided: HookProvided) => mixed;

type Props = {|
...Hooks,
Expand Down Expand Up @@ -758,7 +758,7 @@ Unfortunately we are [unable to apply this optimisation for you](https://medium.

`Draggable` components can be dragged around and dropped onto `Droppable`s. A `Draggable` must always be contained within a `Droppable`. It is **possible** to reorder a `Draggable` within its home `Droppable` or move to another `Droppable`. It is **possible** because a `Droppable` is free to control what it allows to be dropped on it.

Every `Draggable` has a _drag handle_. A _drag handle_ is the element that the user interacts with in order to drag a `Draggable`. A _drag handle_ can be a the `Draggable` element itself, or a child of the `Draggable`.
Every `Draggable` has a _drag handle_. A _drag handle_ is the element that the user interacts with in order to drag a `Draggable`. A _drag handle_ can be a the `Draggable` element itself, or a child of the `Draggable`. Note that by default a _drag handle_ cannot be an interactive element, since [event handlers are blocked on nested interactive elements](#interactive-child-elements-within-a-draggable). Proper semantics for accessibility are added to the _drag handle_ element. If you wish to use an interactive element, `disableInteractiveElementBlocking` must be set.

```js
import { Draggable } from 'react-beautiful-dnd';
Expand Down
14 changes: 9 additions & 5 deletions docs/guides/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ All hooks (except for `onBeforeDragStart`) are provided with a second argument:
## `onDragStart` (optional)

```js
type OnDragStartHook = (start: DragStart, provided: HookProvided) => void;
type OnDragStartHook = (start: DragStart, provided: HookProvided) => mixed;
```

`onDragStart` will get notified when a drag starts. This hook is _optional_ and therefore does not need to be provided. It is **highly recommended** that you use this function to block updates to all `Draggable` and `Droppable` components during a drag. (See **Block updates during a drag** below)
Expand All @@ -58,8 +58,10 @@ type DragStart = {|

### `onDragStart` type information

**Note:** while the return type is `mixed`, the return value is not used.

```js
type OnDragStartHook = (start: DragStart, provided: HookProvided) => void;
type OnDragStartHook = (start: DragStart, provided: HookProvided) => mixed;

// supporting types
type DragStart = {|
Expand All @@ -82,7 +84,7 @@ type TypeId = Id;
## `onDragUpdate` (optional)

```js
type OnDragUpdateHook = (update: DragUpdate, provided: HookProvided) => void;
type OnDragUpdateHook = (update: DragUpdate, provided: HookProvided) => mixed;
```

This hook is called whenever something changes during a drag. The possible changes are:
Expand All @@ -91,7 +93,7 @@ This hook is called whenever something changes during a drag. The possible chang
- The `Draggable` is now over a different `Droppable`
- The `Draggable` is now over no `Droppable`

It is important that you not do too much work as a result of this function as it will slow down the drag.
It is important that you not do too much work as a result of this function as it will slow down the drag. While the return type is `mixed`, the return value is not used.

### `update: DragUpdate`

Expand Down Expand Up @@ -144,9 +146,11 @@ Once we have all of the information we need to start a drag we call the `onBefor

### `OnBeforeDragStartHook` type information

**Note:** while the return type is `mixed`, the return value is not used.

```js
// No second 'provided' argument
type OnBeforeDragStartHook = (start: DragStart) => void;
type OnBeforeDragStartHook = (start: DragStart) => mixed;

// Otherwise the same type information as OnDragStartHook
```
Expand Down
8 changes: 4 additions & 4 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,19 @@ export type HookProvided = {|
announce: Announce,
|};

export type OnBeforeDragStartHook = (start: DragStart) => void;
export type OnBeforeDragStartHook = (start: DragStart) => mixed;
export type OnDragStartHook = (
start: DragStart,
provided: HookProvided,
) => void;
) => mixed;
export type OnDragUpdateHook = (
update: DragUpdate,
provided: HookProvided,
) => void;
) => mixed;
export type OnDragEndHook = (
result: DropResult,
provided: HookProvided,
) => void;
) => mixed;

export type Hooks = {|
onBeforeDragStart?: OnBeforeDragStartHook,
Expand Down