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

Add disableAutoscroll #484

Merged
merged 2 commits into from
Feb 7, 2019
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ There are already a number of great Drag & Drop libraries out there (for instanc
| getContainer | Function | | Optional function to return the scrollable container element. This property defaults to the `SortableContainer` element itself or (if `useWindowAsScrollContainer` is true) the window. Use this function to specify a custom container object (eg this is useful for integrating with certain 3rd party components such as `FlexTable`). This function is passed a single parameter (the `wrappedInstance` React element) and it is expected to return a DOM element. |
| getHelperDimensions | Function | [Function](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L74-L77) | Optional `function({node, index, collection})` that should return the computed dimensions of the SortableHelper. See [default implementation](https://github.com/clauderic/react-sortable-hoc/blob/master/src/SortableContainer/index.js#L74-L77) for more details |
| helperContainer | HTMLElement \| Function | `document.body` | By default, the cloned sortable helper is appended to the document body. Use this prop to specify a different container for the sortable clone to be appended to. Accepts an `HTMLElement` or a function returning an `HTMLElement` that will be invoked before right before sorting begins |
| disableAutoscroll | Boolean | `false` | Disables autoscrolling while dragging |

\* `OffsetValue` can either be a finite `Number` or a `String` made up of a number and a unit (`px` or `%`).
Examples: `10` (which is the same as `"10px"`), `"50%"`
Expand Down
23 changes: 20 additions & 3 deletions src/SortableContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function sortableContainer(
width: node.offsetWidth,
height: node.offsetHeight,
}),
disableAutoscroll: false,
};

static propTypes = {
Expand Down Expand Up @@ -111,6 +112,7 @@ export default function sortableContainer(
? PropTypes.any
: PropTypes.instanceOf(HTMLElement),
]),
disableAutoscroll: PropTypes.bool,
};

static childContextTypes = {
Expand Down Expand Up @@ -764,6 +766,12 @@ export default function sortableContainer(
}

autoscroll = () => {
const {disableAutoscroll} = this.props;

if (disableAutoscroll) {
return;
}

const translate = this.translate;
const direction = {
x: 0,
Expand Down Expand Up @@ -800,23 +808,32 @@ export default function sortableContainer(
Math.abs(
(this.maxTranslate.y - this.height / 2 - translate.y) / this.height,
);
} else if (translate.x >= this.maxTranslate.x - this.width / 2 && !isRight) {
} else if (
translate.x >= this.maxTranslate.x - this.width / 2 &&
!isRight
) {
// Scroll Right
direction.x = 1;
speed.x =
acceleration.x *
Math.abs(
(this.maxTranslate.x - this.width / 2 - translate.x) / this.width,
);
} else if (translate.y <= this.minTranslate.y + this.height / 2 && !isTop) {
} else if (
translate.y <= this.minTranslate.y + this.height / 2 &&
!isTop
) {
// Scroll Up
direction.y = -1;
speed.y =
acceleration.y *
Math.abs(
(translate.y - this.height / 2 - this.minTranslate.y) / this.height,
);
} else if (translate.x <= this.minTranslate.x + this.width / 2 && !isLeft) {
} else if (
translate.x <= this.minTranslate.x + this.width / 2 &&
!isLeft
) {
// Scroll Left
direction.x = -1;
speed.x =
Expand Down