Skip to content

Commit 7845e76

Browse files
superandrew213Claudéric Demers
authored and
Claudéric Demers
committed
feat: Add disableAutoscroll prop (#484)
1 parent 09fbe2b commit 7845e76

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ There are already a number of great Drag & Drop libraries out there (for instanc
120120
| 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. |
121121
| 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 |
122122
| 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 |
123+
| disableAutoscroll | Boolean | `false` | Disables autoscrolling while dragging |
123124

124125
\* `OffsetValue` can either be a finite `Number` or a `String` made up of a number and a unit (`px` or `%`).
125126
Examples: `10` (which is the same as `"10px"`), `"50%"`

src/SortableContainer/index.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default function sortableContainer(
7575
width: node.offsetWidth,
7676
height: node.offsetHeight,
7777
}),
78+
disableAutoscroll: false,
7879
};
7980

8081
static propTypes = {
@@ -111,6 +112,7 @@ export default function sortableContainer(
111112
? PropTypes.any
112113
: PropTypes.instanceOf(HTMLElement),
113114
]),
115+
disableAutoscroll: PropTypes.bool,
114116
};
115117

116118
static childContextTypes = {
@@ -764,6 +766,12 @@ export default function sortableContainer(
764766
}
765767

766768
autoscroll = () => {
769+
const {disableAutoscroll} = this.props;
770+
771+
if (disableAutoscroll) {
772+
return;
773+
}
774+
767775
const translate = this.translate;
768776
const direction = {
769777
x: 0,
@@ -800,23 +808,32 @@ export default function sortableContainer(
800808
Math.abs(
801809
(this.maxTranslate.y - this.height / 2 - translate.y) / this.height,
802810
);
803-
} else if (translate.x >= this.maxTranslate.x - this.width / 2 && !isRight) {
811+
} else if (
812+
translate.x >= this.maxTranslate.x - this.width / 2 &&
813+
!isRight
814+
) {
804815
// Scroll Right
805816
direction.x = 1;
806817
speed.x =
807818
acceleration.x *
808819
Math.abs(
809820
(this.maxTranslate.x - this.width / 2 - translate.x) / this.width,
810821
);
811-
} else if (translate.y <= this.minTranslate.y + this.height / 2 && !isTop) {
822+
} else if (
823+
translate.y <= this.minTranslate.y + this.height / 2 &&
824+
!isTop
825+
) {
812826
// Scroll Up
813827
direction.y = -1;
814828
speed.y =
815829
acceleration.y *
816830
Math.abs(
817831
(translate.y - this.height / 2 - this.minTranslate.y) / this.height,
818832
);
819-
} else if (translate.x <= this.minTranslate.x + this.width / 2 && !isLeft) {
833+
} else if (
834+
translate.x <= this.minTranslate.x + this.width / 2 &&
835+
!isLeft
836+
) {
820837
// Scroll Left
821838
direction.x = -1;
822839
speed.x =

0 commit comments

Comments
 (0)