Skip to content

Commit fee5f13

Browse files
authored
fix: Modify Drag values according to containerPadding (react-grid-layout#1323)
* fix: Modify Drag values according to containerPadding * destructuring assignment containerPadding * FIX: props containerPadding destructuring
1 parent 0f6b18d commit fee5f13

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/GridItem.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,23 +503,24 @@ export default class GridItem extends React.Component<Props, State> {
503503
const { offsetParent } = node;
504504

505505
if (offsetParent) {
506-
const { margin, rowHeight } = this.props;
506+
const { margin, rowHeight, containerPadding } = this.props;
507507
const bottomBoundary =
508508
offsetParent.clientHeight - calcGridItemWHPx(h, rowHeight, margin[1]);
509-
top = clamp(top, 0, bottomBoundary);
509+
top = clamp(top - containerPadding[1], 0, bottomBoundary);
510510

511511
const colWidth = calcGridColWidth(positionParams);
512512
const rightBoundary =
513513
containerWidth - calcGridItemWHPx(w, colWidth, margin[0]);
514-
left = clamp(left, 0, rightBoundary);
514+
left = clamp(left - containerPadding[0], 0, rightBoundary);
515515
}
516516
}
517517

518518
const newPosition: PartialPosition = { top, left };
519519
this.setState({ dragging: newPosition });
520520

521521
// Call callback with this data
522-
const { x, y } = calcXY(positionParams, top, left, w, h);
522+
const { containerPadding } = this.props;
523+
const { x, y } = calcXY(positionParams, top - containerPadding[1], left - containerPadding[0], w, h);
523524
return onDrag.call(this, i, x, y, {
524525
e,
525526
node,
@@ -539,12 +540,12 @@ export default class GridItem extends React.Component<Props, State> {
539540
if (!this.state.dragging) {
540541
throw new Error("onDragEnd called before onDragStart.");
541542
}
542-
const { w, h, i } = this.props;
543+
const { w, h, i, containerPadding } = this.props;
543544
const { left, top } = this.state.dragging;
544545
const newPosition: PartialPosition = { top, left };
545546
this.setState({ dragging: null });
546547

547-
const { x, y } = calcXY(this.getPositionParams(), top, left, w, h);
548+
const { x, y } = calcXY(this.getPositionParams(), top - containerPadding[1], left - containerPadding[0], w, h);
548549

549550
return onDragStop.call(this, i, x, y, {
550551
e,

0 commit comments

Comments
 (0)