Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 43b34fa

Browse files
aldo-romanThomasBurleson
authored andcommitted
fix(fxLayoutGap): update gap logic when num children reduces to 1.
Fixes #433. Closes #444.
1 parent 7dcd97b commit 43b34fa

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/lib/api/flexbox/layout-gap.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,37 @@ describe('layout-gap directive', () => {
140140

141141
}));
142142

143+
fit('should add update gap styles when only 1 row is remaining', async(() => {
144+
let template = `
145+
<div fxLayoutAlign='center center' fxLayoutGap='13px'>
146+
<div fxFlex *ngFor='let row of rows'></div>
147+
</div>
148+
`;
149+
fixture = createTestComponent(template);
150+
fixture.componentInstance.direction = 'row';
151+
fixture.detectChanges();
152+
153+
let nodes = queryFor(fixture, '[fxFlex]');
154+
155+
expect(nodes.length).toEqual(4);
156+
expect(nodes[0].nativeElement).toHaveStyle({'margin-right': '13px'});
157+
expect(nodes[3].nativeElement).not.toHaveStyle({'margin-right': '13px'});
158+
159+
fixture.componentInstance.rows = new Array(1);
160+
fixture.detectChanges();
161+
162+
setTimeout(() => {
163+
// Since the layoutGap directive detects the *ngFor changes by using a MutationObserver, the
164+
// browser will take up some time, to actually announce the changes to the directive.
165+
// (Kudos to @DevVersion)
166+
nodes = queryFor(fixture, '[fxFlex]');
167+
168+
expect(nodes.length).toEqual(1);
169+
expect(nodes[0].nativeElement).not.toHaveStyle({'margin-right': '13px'});
170+
});
171+
172+
}));
173+
143174
it('should apply margin-top for column layouts', () => {
144175
verifyCorrectMargin('column', 'margin-bottom');
145176
});

src/lib/api/flexbox/layout-gap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class LayoutGapDirective extends BaseFxDirective implements AfterContentI
160160
.filter(el => el.nodeType === 1 && this._getDisplayStyle(el) != 'none');
161161
let numItems = items.length;
162162

163-
if (numItems > 1) {
163+
if (numItems > 0) {
164164
let lastItem = items[numItems - 1];
165165

166166
// For each `element` children EXCEPT the last,

0 commit comments

Comments
 (0)