@@ -157,11 +157,29 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
157
157
// The flex-direction of this element's flex container. Defaults to 'row'.
158
158
let layout = this . _getFlowDirection ( this . parentElement , true ) ;
159
159
let direction = ( layout . indexOf ( 'column' ) > - 1 ) ? 'column' : 'row' ;
160
- let css , isValue ;
160
+
161
+ let max = isFlowHorizontal ( direction ) ? 'max-width' : 'max-height' ;
162
+ let min = isFlowHorizontal ( direction ) ? 'min-width' : 'min-height' ;
163
+
164
+ let hasCalc = String ( basis ) . indexOf ( 'calc' ) > - 1 ;
165
+ let usingCalc = hasCalc || ( basis == 'auto' ) ;
166
+ let isPercent = String ( basis ) . indexOf ( '%' ) > - 1 && ! hasCalc ;
167
+ let hasUnits = String ( basis ) . indexOf ( 'px' ) > - 1 || String ( basis ) . indexOf ( 'em' ) > - 1 ||
168
+ String ( basis ) . indexOf ( 'vw' ) > - 1 || String ( basis ) . indexOf ( 'vh' ) > - 1 ;
169
+ let isPx = String ( basis ) . indexOf ( 'px' ) > - 1 || usingCalc ;
170
+
171
+ let isValue = ( hasCalc || hasUnits ) ;
161
172
162
173
grow = ( grow == '0' ) ? 0 : grow ;
163
174
shrink = ( shrink == '0' ) ? 0 : shrink ;
164
175
176
+ // make box inflexible when shrink and grow are both zero
177
+ // should not set a min when the grow is zero
178
+ // should not set a max when the shrink is zero
179
+ let isFixed = ! grow && ! shrink ;
180
+
181
+ let css = { } ;
182
+
165
183
// flex-basis allows you to specify the initial/starting main-axis size of the element,
166
184
// before anything else is computed. It can either be a percentage or an absolute value.
167
185
// It is, however, not the breaking point for flex-grow/shrink properties
@@ -182,68 +200,94 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
182
200
} ;
183
201
switch ( basis || '' ) {
184
202
case '' :
185
- css = extendObject ( clearStyles , { 'flex' : ` ${ grow } ${ shrink } 0.000000001px` } ) ;
203
+ basis = ' 0.000000001px' ;
186
204
break ;
187
205
case 'initial' : // default
188
206
case 'nogrow' :
189
207
grow = 0 ;
190
- css = extendObject ( clearStyles , { 'flex' : '0 1 auto'} ) ;
208
+ basis = ' auto';
191
209
break ;
192
210
case 'grow' :
193
- css = extendObject ( clearStyles , { 'flex' : '1 1 100%'} ) ;
211
+ basis = ' 100%';
194
212
break ;
195
213
case 'noshrink' :
196
214
shrink = 0 ;
197
- css = extendObject ( clearStyles , { 'flex' : '1 0 auto'} ) ;
215
+ basis = ' auto';
198
216
break ;
199
217
case 'auto' :
200
- css = extendObject ( clearStyles , { 'flex' : `${ grow } ${ shrink } auto` } ) ;
201
218
break ;
202
219
case 'none' :
203
220
grow = 0 ;
204
221
shrink = 0 ;
205
- css = extendObject ( clearStyles , { 'flex' : '0 0 auto'} ) ;
222
+ basis = ' auto';
206
223
break ;
207
224
default :
208
- let hasCalc = String ( basis ) . indexOf ( 'calc' ) > - 1 ;
209
- let isPercent = String ( basis ) . indexOf ( '%' ) > - 1 && ! hasCalc ;
210
-
211
- isValue = hasCalc ||
212
- String ( basis ) . indexOf ( 'px' ) > - 1 ||
213
- String ( basis ) . indexOf ( 'em' ) > - 1 ||
214
- String ( basis ) . indexOf ( 'vw' ) > - 1 ||
215
- String ( basis ) . indexOf ( 'vh' ) > - 1 ;
216
-
217
225
// Defaults to percentage sizing unless `px` is explicitly set
218
226
if ( ! isValue && ! isPercent && ! isNaN ( basis as any ) ) {
219
227
basis = basis + '%' ;
220
228
}
221
229
230
+ // Fix for issue 280
231
+ if ( basis === '0%' ) {
232
+ isValue = true ;
233
+ }
234
+
222
235
if ( basis === '0px' ) {
223
236
basis = '0%' ;
224
237
}
225
238
226
- css = extendObject ( clearStyles , { // fix issue #5345
227
- 'flex' : `${ grow } ${ shrink } ${ isValue ? basis : '100%' } `
228
- } ) ;
239
+ // fix issue #5345
240
+ if ( hasCalc ) {
241
+ css = extendObject ( clearStyles , {
242
+ 'flex-grow' : grow ,
243
+ 'flex-shrink' : shrink ,
244
+ 'flex-basis' : isValue ? basis : '100%'
245
+ } ) ;
246
+ } else {
247
+ css = extendObject ( clearStyles , {
248
+ 'flex' : `${ grow } ${ shrink } ${ isValue ? basis : '100%' } `
249
+ } ) ;
250
+ }
251
+
229
252
break ;
230
253
}
231
254
232
- let max = isFlowHorizontal ( direction ) ? 'max-width' : 'max-height' ;
233
- let min = isFlowHorizontal ( direction ) ? 'min-width' : 'min-height' ;
234
-
235
- let usingCalc = ( String ( basis ) . indexOf ( 'calc' ) > - 1 ) || ( basis == 'auto' ) ;
236
- let isPx = String ( basis ) . indexOf ( 'px' ) > - 1 || usingCalc ;
255
+ if ( ! ( css [ 'flex' ] || css [ 'flex-grow' ] ) ) {
256
+ if ( hasCalc ) {
257
+ css = extendObject ( clearStyles , {
258
+ 'flex-grow' : grow ,
259
+ 'flex-shrink' : shrink ,
260
+ 'flex-basis' : basis
261
+ } ) ;
262
+ } else {
263
+ css = extendObject ( clearStyles , {
264
+ 'flex' : `${ grow } ${ shrink } ${ basis } `
265
+ } ) ;
266
+ }
267
+ }
237
268
269
+ // Fix for issues 277 and 534
270
+ // TODO(CaerusKaru): convert this to just width/height
271
+ if ( basis !== '0%' ) {
272
+ css [ min ] = isFixed || ( isPx && grow ) ? basis : null ;
273
+ css [ max ] = isFixed || ( ! usingCalc && shrink ) ? basis : null ;
274
+ }
238
275
239
- // make box inflexible when shrink and grow are both zero
240
- // should not set a min when the grow is zero
241
- // should not set a max when the shrink is zero
242
- let isFixed = ! grow && ! shrink ;
243
- css [ min ] = ( basis == '0%' ) ? 0 : isFixed || ( isPx && grow ) ? basis : null ;
244
- css [ max ] = ( basis == '0%' ) ? 0 : isFixed || ( ! usingCalc && shrink ) ? basis : null ;
276
+ // Fix for issue 528
277
+ if ( ! css [ min ] && ! css [ max ] ) {
278
+ if ( hasCalc ) {
279
+ css = extendObject ( clearStyles , {
280
+ 'flex-grow' : grow ,
281
+ 'flex-shrink' : shrink ,
282
+ 'flex-basis' : basis
283
+ } ) ;
284
+ } else {
285
+ css = extendObject ( clearStyles , {
286
+ 'flex' : `${ grow } ${ shrink } ${ basis } `
287
+ } ) ;
288
+ }
289
+ }
245
290
246
291
return extendObject ( css , { 'box-sizing' : 'border-box' } ) ;
247
292
}
248
-
249
293
}
0 commit comments