Skip to content

Commit

Permalink
fix: Modify Drag values according to containerPadding (#1323)
Browse files Browse the repository at this point in the history
* fix: Modify Drag values according to containerPadding

* destructuring assignment containerPadding

* FIX: props containerPadding destructuring
  • Loading branch information
hywlss9 committed Nov 24, 2023
1 parent 0f6b18d commit fee5f13
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/GridItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,24 @@ export default class GridItem extends React.Component<Props, State> {
const { offsetParent } = node;

if (offsetParent) {
const { margin, rowHeight } = this.props;
const { margin, rowHeight, containerPadding } = this.props;
const bottomBoundary =
offsetParent.clientHeight - calcGridItemWHPx(h, rowHeight, margin[1]);
top = clamp(top, 0, bottomBoundary);
top = clamp(top - containerPadding[1], 0, bottomBoundary);

const colWidth = calcGridColWidth(positionParams);
const rightBoundary =
containerWidth - calcGridItemWHPx(w, colWidth, margin[0]);
left = clamp(left, 0, rightBoundary);
left = clamp(left - containerPadding[0], 0, rightBoundary);
}
}

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

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

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

return onDragStop.call(this, i, x, y, {
e,
Expand Down

0 comments on commit fee5f13

Please sign in to comment.