Skip to content

Commit

Permalink
- take parent gap style into account when container is a flexbox
Browse files Browse the repository at this point in the history
- more strict hiding styles for the dragged item
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Apr 22, 2022
1 parent 9fe41b6 commit a769a4f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/dragsort.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/dragsort.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/dragsort.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
.dragsort--dragStart .dragsort--hide {
width: 0 !important;
height: 0 !important;
/* padding: 0;
margin: 0;
border-width: 0; */
padding: 0 !important;
margin: 0 !important;
border-width: 0 !important;
}

.dragsort--dragStart > *{
transition: .18s cubic-bezier(.6, .1, .4, 1.2);
transition: var(--dragsort-trans-dur, .18s) cubic-bezier(.6, .1, .4, 1.2);
}

.dragsort--dragStart > * > *{
Expand Down
12 changes: 8 additions & 4 deletions src/dragsort.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,14 @@
},

getItemsGap(elm) {
var styles = getComputedStyle(elm);
return this.settings.mode == 'vertical' ?
parseInt(styles.marginTop) + parseInt(styles.marginBottom) :
parseInt(styles.marginLeft) + parseInt(styles.marginRight)
var itemStyles = getComputedStyle(elm),
parentStyles = getComputedStyle(elm.parentNode),
v = this.settings.mode == 'vertical',
gap = parseInt(parentStyles.gap) || 0, // parent might be a flexbox witha a gap
marginGap = parseInt(itemStyles[`margin${v ? 'Top' : 'Left'}`]) +
parseInt(itemStyles[`margin${v ? 'Bottom' : 'Right'}`])

return marginGap + gap;
},

bindEvents(unbind) {
Expand Down
18 changes: 12 additions & 6 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ <h2>Horizontal Tags - Varying Widths</h2>
}

.list {
--gap: 1vw;

display: flex;
flex-wrap: wrap;
gap: var(--gap);
padding: var(--gap);

width: 100%;
max-width: 600px;
margin: 2rem auto;
padding: 0;
list-style-type: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
user-select: none;
overflow: hidden;
}

Expand Down Expand Up @@ -93,11 +96,14 @@ <h2>Horizontal Tags - Varying Widths</h2>
font-weight: bold;
border-radius: 20px;
padding: 0.3em 0.5em;
margin: 5px 0 5px 5px;
white-space: nowrap;
box-sizing: border-box;
overflow: hidden;
}

.card.dragsort--hide {
margin: 0 calc(var(--gap)/2 * -1);
}
</style>
<script>
DragSort( document.querySelector('.list') )
Expand Down

0 comments on commit a769a4f

Please sign in to comment.