@@ -39,8 +39,8 @@ import {StyleUtils} from '../../utils/styling/style-utils';
39
39
[fxLayoutGap.gt-xs], [fxLayoutGap.gt-sm], [fxLayoutGap.gt-md], [fxLayoutGap.gt-lg]
40
40
`
41
41
} )
42
- export class LayoutGapDirective extends BaseFxDirective implements AfterContentInit , OnChanges ,
43
- OnDestroy {
42
+ export class LayoutGapDirective extends BaseFxDirective
43
+ implements AfterContentInit , OnChanges , OnDestroy {
44
44
protected _layout = 'row' ; // default flex-direction
45
45
protected _layoutWatcher : Subscription ;
46
46
protected _observer : MutationObserver ;
@@ -128,7 +128,7 @@ export class LayoutGapDirective extends BaseFxDirective implements AfterContentI
128
128
129
129
if ( typeof MutationObserver !== 'undefined' ) {
130
130
this . _observer = new MutationObserver ( ( mutations : MutationRecord [ ] ) => {
131
- let validatedChanges = ( it : MutationRecord ) : boolean => {
131
+ const validatedChanges = ( it : MutationRecord ) : boolean => {
132
132
return ( it . addedNodes && it . addedNodes . length > 0 ) ||
133
133
( it . removedNodes && it . removedNodes . length > 0 ) ;
134
134
} ;
@@ -164,16 +164,23 @@ export class LayoutGapDirective extends BaseFxDirective implements AfterContentI
164
164
}
165
165
166
166
// Gather all non-hidden Element nodes
167
- let items = this . childrenNodes
168
- . filter ( el => el . nodeType === 1 && this . _getDisplayStyle ( el ) != 'none' ) ;
169
- let numItems = items . length ;
170
-
171
- if ( numItems > 0 ) {
172
- let lastItem = items [ numItems - 1 ] ;
167
+ const items = this . childrenNodes
168
+ . filter ( el => el . nodeType === 1 && this . _getDisplayStyle ( el ) != 'none' )
169
+ . sort ( ( a , b ) => {
170
+ const orderA = + this . _styler . lookupStyle ( a , 'order' ) ;
171
+ const orderB = + this . _styler . lookupStyle ( b , 'order' ) ;
172
+ if ( isNaN ( orderA ) || isNaN ( orderB ) || orderA === orderB ) {
173
+ return 0 ;
174
+ } else {
175
+ return orderA > orderB ? 1 : - 1 ;
176
+ }
177
+ } ) ;
178
+
179
+ if ( items . length > 0 ) {
180
+ const lastItem = items . pop ( ) ;
173
181
174
182
// For each `element` children EXCEPT the last,
175
183
// set the margin right/bottom styles...
176
- items = items . filter ( ( _ , j ) => j < numItems - 1 ) ;
177
184
this . _applyStyleToElements ( this . _buildCSS ( value ) , items ) ;
178
185
179
186
// Clear all gaps for all visible elements
0 commit comments