This repository was archived by the owner on Jan 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
projects/libs/flex-layout Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export interface LayoutConfigOptions {
2020 mediaTriggerAutoRestore ?: boolean ;
2121 ssrObserveBreakpoints ?: string [ ] ;
2222 multiplier ?: Multiplier ;
23+ defaultUnit ?: string ;
2324}
2425
2526export const DEFAULT_CONFIG : Required < LayoutConfigOptions > = {
@@ -36,6 +37,7 @@ export const DEFAULT_CONFIG: Required<LayoutConfigOptions> = {
3637 // run for all users, regardless of whether they're using this feature.
3738 // Instead, we disable it by default, which requires this ugly cast.
3839 multiplier : undefined as unknown as Multiplier ,
40+ defaultUnit : 'px' ,
3941} ;
4042
4143export const LAYOUT_CONFIG = new InjectionToken < LayoutConfigOptions > (
Original file line number Diff line number Diff line change @@ -135,6 +135,25 @@ describe('layout-gap directive', () => {
135135 expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '0px' } , styler ) ;
136136 } ) ;
137137
138+ it ( 'should add gap styles to all children except the 1st child w/o unit' , ( ) => {
139+ let template = `
140+ <div fxLayoutAlign='center center' fxLayoutGap='13'>
141+ <div fxFlex></div>
142+ <div fxFlex></div>
143+ <div fxFlex></div>
144+ </div>
145+ ` ;
146+ createTestComponent ( template ) ;
147+ fixture . detectChanges ( ) ;
148+
149+ let nodes = queryFor ( fixture , '[fxFlex]' ) ;
150+ expect ( nodes . length ) . toEqual ( 3 ) ;
151+ expectEl ( nodes [ 0 ] ) . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
152+ expectEl ( nodes [ 1 ] ) . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
153+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '13px' } , styler ) ;
154+ expectEl ( nodes [ 2 ] ) . not . toHaveStyle ( { 'margin-right' : '0px' } , styler ) ;
155+ } ) ;
156+
138157 it ( 'should add gap styles in proper order when order style is applied' , ( ) => {
139158 let template = `
140159 <div fxLayoutAlign='center center' fxLayoutGap='13px'>
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ export class LayoutGapStyleBuilder extends StyleBuilder {
7373 this . _styler . applyStyleToElements ( paddingStyles , parent . items ) ;
7474 } else {
7575 gapValue = multiply ( gapValue , this . _config . multiplier ) ;
76+ gapValue = this . addFallbackUnit ( gapValue ) ;
77+
7678 const lastItem = items . pop ( ) ! ;
7779
7880 // For each `element` children EXCEPT the last,
@@ -84,6 +86,10 @@ export class LayoutGapStyleBuilder extends StyleBuilder {
8486 this . _styler . applyStyleToElements ( CLEAR_MARGIN_CSS , [ lastItem ] ) ;
8587 }
8688 }
89+
90+ private addFallbackUnit ( value : string ) {
91+ return ! isNaN ( + value ) ? `${ value } ${ this . _config . defaultUnit } ` : value ;
92+ }
8793}
8894
8995const inputs = [
You can’t perform that action at this time.
0 commit comments