Skip to content

Commit 83a20c6

Browse files
committed
fix(collectionRepeat): fix a dom problem with margins and position:relative
Closes #3277.
1 parent 2c2662f commit 83a20c6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: js/angular/directive/collectionRepeat.js

+12
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
483483
repeaterBeforeSize += current[isVertical ? 'offsetTop' : 'offsetLeft'];
484484
} while( ionic.DomUtil.contains(scrollView.__content, current = current.offsetParent) );
485485

486+
var containerPrevNode = containerNode.previousElementSibling;
487+
var beforeStyle = containerPrevNode ? $window.getComputedStyle(containerPrevNode) : {};
488+
var beforeMargin = parseInt(beforeStyle[isVertical ? 'marginBottom' : 'marginRight'] || 0);
489+
490+
// Because we position the collection container with position: relative, it doesn't take
491+
// into account where to position itself relative to the previous element's marginBottom.
492+
// To compensate, we translate the container up by the previous element's margin.
493+
containerNode.style[ionic.CSS.TRANSFORM] = TRANSLATE_TEMPLATE_STR
494+
.replace(PRIMARY, -beforeMargin)
495+
.replace(SECONDARY, 0);
496+
repeaterBeforeSize -= beforeMargin;
497+
486498
if (!scrollView.__clientHeight || !scrollView.__clientWidth) {
487499
scrollView.__clientWidth = scrollView.__container.clientWidth;
488500
scrollView.__clientHeight = scrollView.__container.clientHeight;

Diff for: test/html/collection-repeat/basic-list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<h1 class="title">Basic List: Static Dimensions</h1>
1818
</ion-header-bar>
1919
<ion-content>
20-
<h4>WHATS UP</h4>
20+
<h4 style="margin: 80px;">I have 80px margin</h4>
2121
<ion-list can-swipe="true" show-delete="$root.showDelete">
2222
<ion-item class="item" collection-repeat="item in items">
2323
<ion-option-button>Button</ion-option-button>

0 commit comments

Comments
 (0)