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

fix(layout-align): respect inline-flex on sibling fxLayout #1036

Merged
merged 4 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/flex/layout-align/layout-align.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ describe('layout-align directive', () => {
'align-content': 'stretch'
}, styler);
});
it('should add preserve fxLayout in inline mode', () => {
createTestComponent(`<div fxLayout='column inline' fxLayoutAlign></div>`);
expectNativeEl(fixture).toHaveStyle({
'display': 'inline-flex',
'flex-direction': 'column',
'box-sizing': 'border-box',
'justify-content': 'flex-start',
'align-items': 'stretch',
'align-content': 'stretch'
}, styler);
});

describe('for "main-axis" testing', () => {
it('should add correct styles for `fxLayoutAlign="start"` usage', () => {
Expand Down
32 changes: 24 additions & 8 deletions src/lib/flex/layout-align/layout-align.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {LAYOUT_VALUES, isFlowHorizontal} from '../../utils/layout-validator';

export interface LayoutAlignParent {
layout: string;
inline: boolean;
}

@Injectable({providedIn: 'root'})
Expand Down Expand Up @@ -85,7 +86,7 @@ export class LayoutAlignStyleBuilder extends StyleBuilder {
}

return extendObject(css, {
'display' : 'flex',
'display' : parent.inline ? 'inline-flex' : 'flex',
'flex-direction' : parent.layout,
'box-sizing' : 'border-box',
'max-width': crossAxis === 'stretch' ?
Expand Down Expand Up @@ -121,6 +122,7 @@ const selector = `
export class LayoutAlignDirective extends BaseDirective2 {
protected DIRECTIVE_KEY = 'layout-align';
protected layout = 'row'; // default flex-direction
protected inline = false; // default inline value

constructor(protected elRef: ElementRef,
protected styleUtils: StyleUtils,
Expand All @@ -144,24 +146,34 @@ export class LayoutAlignDirective extends BaseDirective2 {
*/
protected updateWithValue(value: string) {
const layout = this.layout || 'row';
if (layout === 'row') {
const inline = this.inline;
if (layout === 'row' && inline) {
this.styleCache = layoutAlignHorizontalInlineCache;
} else if (layout === 'row' && !inline) {
this.styleCache = layoutAlignHorizontalCache;
} else if (layout === 'row-reverse') {
} else if (layout === 'row-reverse' && inline) {
this.styleCache = layoutAlignHorizontalRevInlineCache;
} else if (layout === 'row-reverse' && !inline) {
this.styleCache = layoutAlignHorizontalRevCache;
} else if (layout === 'column') {
} else if (layout === 'column' && inline) {
this.styleCache = layoutAlignVerticalInlineCache;
} else if (layout === 'column' && !inline) {
this.styleCache = layoutAlignVerticalCache;
} else if (layout === 'column-reverse') {
} else if (layout === 'column-reverse' && inline) {
this.styleCache = layoutAlignVerticalRevInlineCache;
} else if (layout === 'column-reverse' && !inline) {
this.styleCache = layoutAlignVerticalRevCache;
}
this.addStyles(value, {layout});
this.addStyles(value, {layout, inline});
}

/**
* Cache the parent container 'flex-direction' and update the 'flex' styles
*/
protected onLayoutChange(matcher: ElementMatcher) {
const layout: string = matcher.value;
this.layout = layout.split(' ')[0];
const layoutKeys: string[] = matcher.value.split(' ');
this.layout = layoutKeys[0];
this.inline = matcher.value.includes('inline');
if (!LAYOUT_VALUES.find(x => x === this.layout)) {
this.layout = 'row';
}
Expand All @@ -178,3 +190,7 @@ const layoutAlignHorizontalCache: Map<string, StyleDefinition> = new Map();
const layoutAlignVerticalCache: Map<string, StyleDefinition> = new Map();
const layoutAlignHorizontalRevCache: Map<string, StyleDefinition> = new Map();
const layoutAlignVerticalRevCache: Map<string, StyleDefinition> = new Map();
const layoutAlignHorizontalInlineCache: Map<string, StyleDefinition> = new Map();
const layoutAlignVerticalInlineCache: Map<string, StyleDefinition> = new Map();
const layoutAlignHorizontalRevInlineCache: Map<string, StyleDefinition> = new Map();
const layoutAlignVerticalRevInlineCache: Map<string, StyleDefinition> = new Map();