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

Commit c23621c

Browse files
authored
fix(layout-align): respect inline-flex on sibling fxLayout (#1036)
Before this commit, `fxLayoutAlign` only respected the sibling `fxLayout` direction (including `reverse` attribute), but not the `inline` attribute. This commit corrects that behavior Fixes #1009
1 parent 5112a47 commit c23621c

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/lib/flex/layout-align/layout-align.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ describe('layout-align directive', () => {
8484
'align-content': 'stretch'
8585
}, styler);
8686
});
87+
it('should add preserve fxLayout in inline mode', () => {
88+
createTestComponent(`<div fxLayout='column inline' fxLayoutAlign></div>`);
89+
expectNativeEl(fixture).toHaveStyle({
90+
'display': 'inline-flex',
91+
'flex-direction': 'column',
92+
'box-sizing': 'border-box',
93+
'justify-content': 'flex-start',
94+
'align-items': 'stretch',
95+
'align-content': 'stretch'
96+
}, styler);
97+
});
8798

8899
describe('for "main-axis" testing', () => {
89100
it('should add correct styles for `fxLayoutAlign="start"` usage', () => {

src/lib/flex/layout-align/layout-align.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {LAYOUT_VALUES, isFlowHorizontal} from '../../utils/layout-validator';
2121

2222
export interface LayoutAlignParent {
2323
layout: string;
24+
inline: boolean;
2425
}
2526

2627
@Injectable({providedIn: 'root'})
@@ -85,7 +86,7 @@ export class LayoutAlignStyleBuilder extends StyleBuilder {
8586
}
8687

8788
return extendObject(css, {
88-
'display' : 'flex',
89+
'display' : parent.inline ? 'inline-flex' : 'flex',
8990
'flex-direction' : parent.layout,
9091
'box-sizing' : 'border-box',
9192
'max-width': crossAxis === 'stretch' ?
@@ -121,6 +122,7 @@ const selector = `
121122
export class LayoutAlignDirective extends BaseDirective2 {
122123
protected DIRECTIVE_KEY = 'layout-align';
123124
protected layout = 'row'; // default flex-direction
125+
protected inline = false; // default inline value
124126

125127
constructor(protected elRef: ElementRef,
126128
protected styleUtils: StyleUtils,
@@ -144,24 +146,34 @@ export class LayoutAlignDirective extends BaseDirective2 {
144146
*/
145147
protected updateWithValue(value: string) {
146148
const layout = this.layout || 'row';
147-
if (layout === 'row') {
149+
const inline = this.inline;
150+
if (layout === 'row' && inline) {
151+
this.styleCache = layoutAlignHorizontalInlineCache;
152+
} else if (layout === 'row' && !inline) {
148153
this.styleCache = layoutAlignHorizontalCache;
149-
} else if (layout === 'row-reverse') {
154+
} else if (layout === 'row-reverse' && inline) {
155+
this.styleCache = layoutAlignHorizontalRevInlineCache;
156+
} else if (layout === 'row-reverse' && !inline) {
150157
this.styleCache = layoutAlignHorizontalRevCache;
151-
} else if (layout === 'column') {
158+
} else if (layout === 'column' && inline) {
159+
this.styleCache = layoutAlignVerticalInlineCache;
160+
} else if (layout === 'column' && !inline) {
152161
this.styleCache = layoutAlignVerticalCache;
153-
} else if (layout === 'column-reverse') {
162+
} else if (layout === 'column-reverse' && inline) {
163+
this.styleCache = layoutAlignVerticalRevInlineCache;
164+
} else if (layout === 'column-reverse' && !inline) {
154165
this.styleCache = layoutAlignVerticalRevCache;
155166
}
156-
this.addStyles(value, {layout});
167+
this.addStyles(value, {layout, inline});
157168
}
158169

159170
/**
160171
* Cache the parent container 'flex-direction' and update the 'flex' styles
161172
*/
162173
protected onLayoutChange(matcher: ElementMatcher) {
163-
const layout: string = matcher.value;
164-
this.layout = layout.split(' ')[0];
174+
const layoutKeys: string[] = matcher.value.split(' ');
175+
this.layout = layoutKeys[0];
176+
this.inline = matcher.value.includes('inline');
165177
if (!LAYOUT_VALUES.find(x => x === this.layout)) {
166178
this.layout = 'row';
167179
}
@@ -178,3 +190,7 @@ const layoutAlignHorizontalCache: Map<string, StyleDefinition> = new Map();
178190
const layoutAlignVerticalCache: Map<string, StyleDefinition> = new Map();
179191
const layoutAlignHorizontalRevCache: Map<string, StyleDefinition> = new Map();
180192
const layoutAlignVerticalRevCache: Map<string, StyleDefinition> = new Map();
193+
const layoutAlignHorizontalInlineCache: Map<string, StyleDefinition> = new Map();
194+
const layoutAlignVerticalInlineCache: Map<string, StyleDefinition> = new Map();
195+
const layoutAlignHorizontalRevInlineCache: Map<string, StyleDefinition> = new Map();
196+
const layoutAlignVerticalRevInlineCache: Map<string, StyleDefinition> = new Map();

0 commit comments

Comments
 (0)