Skip to content

Commit 1ef796f

Browse files
Update SwipeableListItem.js
Fix width of swappable items
1 parent cf6ef76 commit 1ef796f

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

src/SwipeableListItem.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,36 @@ class SwipeableListItem extends PureComponent {
502502
this.resetState();
503503
}
504504
}
505+
506+
this.fixFinalWidth();
507+
};
508+
509+
fixFinalWidth = () => {
510+
const { leadingOffset = 0, trailingOffset = 0 } = this.props;
511+
512+
if (this.leadingActionsElement) {
513+
const leadingActionsWidth = parseInt(
514+
this.leadingActionsElement.style.width
515+
);
516+
517+
if (leadingActionsWidth > 0) {
518+
this.leadingActionsElement.style.width = `${
519+
leadingActionsWidth + leadingOffset
520+
}px`;
521+
}
522+
}
523+
524+
if (this.trailingActionsElement) {
525+
const trailingActionsWidth = parseInt(
526+
this.trailingActionsElement.style.width
527+
);
528+
529+
if (trailingActionsWidth > 0) {
530+
this.trailingActionsElement.style.width = `${
531+
trailingActionsWidth + trailingOffset
532+
}px`;
533+
}
534+
}
505535
};
506536

507537
dragStartedWithinItem = () => {
@@ -656,6 +686,8 @@ class SwipeableListItem extends PureComponent {
656686
}px`;
657687
}
658688

689+
this.fixFinalWidth();
690+
659691
if (this.listElement) {
660692
if (fullSwipe) {
661693
const {
@@ -709,7 +741,6 @@ class SwipeableListItem extends PureComponent {
709741
}
710742
}
711743
}
712-
713744
this.startTime = Date.now();
714745
};
715746

@@ -822,6 +853,8 @@ SwipeableListItem.propTypes = {
822853
swipeStartThreshold: PropTypes.number,
823854
threshold: PropTypes.number,
824855
trailingActions: PropTypes.node,
856+
leadingOffset: PropTypes.number,
857+
trailingOffset: PropTypes.number,
825858
};
826859

827860
export default SwipeableListItem;

0 commit comments

Comments
 (0)