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

Commit b201845

Browse files
fix(fxLayout): add support for inline-flex
Flexbox CSS supports `display:inline-flex` to indicate that the flexbox container should be inline; similar to the `display:inline-block`. When used with the **fxLayout** API, this fix will support the **inline** option: * `fxLayout="row inline"` * `fxLayout="column wrap inline"` Fixes #525.
1 parent 82ae74c commit b201845

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

src/lib/api/flexbox/layout.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,71 @@ describe('layout directive', () => {
141141

142142
});
143143

144+
describe('with wrap options', () => {
145+
146+
it('should recognize valid `wrap` option', () => {
147+
createTestComponent(`<div fxLayout='row wrap'></div>`);
148+
expectNativeEl(fixture).toHaveStyle({
149+
'display': 'flex',
150+
'flex-direction': 'row',
151+
'box-sizing': 'border-box',
152+
'flex-wrap': 'wrap'
153+
});
154+
});
155+
156+
it('should fallback to `wrap` for invalid options', () => {
157+
createTestComponent(`<div fxLayout='row warpped'></div>`);
158+
expectNativeEl(fixture).toHaveStyle({
159+
'flex-wrap': 'wrap'
160+
});
161+
});
162+
163+
it('should fallback to `wrap` for invalid options', () => {
164+
createTestComponent(`<div fxLayout='row wrap-rev'></div>`);
165+
expectNativeEl(fixture).toHaveStyle({
166+
'flex-wrap': 'wrap'
167+
});
168+
});
169+
170+
});
171+
172+
describe('with inline options', () => {
173+
174+
it('should recognize valid `inline` option', () => {
175+
createTestComponent(`<div fxLayout='row inline'></div>`);
176+
expectNativeEl(fixture).toHaveStyle({
177+
'display': 'inline-flex',
178+
'flex-direction': 'row'
179+
});
180+
});
181+
182+
it('should recognize `line` used with `wrap`', () => {
183+
createTestComponent(`<div fxLayout='row inline wrap'></div>`);
184+
expectNativeEl(fixture).toHaveStyle({
185+
'display': 'inline-flex',
186+
'flex-wrap': 'wrap'
187+
});
188+
});
189+
190+
it('should recognize `inline` used with `wrap`', () => {
191+
createTestComponent(`<div fxLayout='row wrap inline'></div>`);
192+
expectNativeEl(fixture).toHaveStyle({
193+
'display': 'inline-flex',
194+
'flex-wrap': 'wrap'
195+
});
196+
});
197+
198+
it('should fallback to `wrap` for invalid options', () => {
199+
createTestComponent(`<div fxLayout='row inline wrap-rev'></div>`);
200+
expectNativeEl(fixture).toHaveStyle({
201+
'display': 'inline-flex',
202+
'flex-wrap': 'wrap'
203+
});
204+
});
205+
206+
});
207+
208+
144209
describe('with responsive features', () => {
145210

146211
it('should ignore responsive changes when not configured', () => {

src/lib/utils/layout-validator.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
8+
export const INLINE = 'inline';
99
export const LAYOUT_VALUES = ['row', 'column', 'row-reverse', 'column-reverse'];
1010

1111
/**
1212
* Validate the direction|'direction wrap' value and then update the host's inline flexbox styles
1313
*/
1414
export function buildLayoutCSS(value: string) {
15-
let [direction, wrap] = validateValue(value);
16-
return buildCSS(direction, wrap);
15+
let [direction, wrap, isInline] = validateValue(value);
16+
return buildCSS(direction, wrap, isInline);
1717
}
1818

1919
/**
@@ -22,11 +22,19 @@ export function buildLayoutCSS(value: string) {
2222
*/
2323
export function validateValue(value: string) {
2424
value = value ? value.toLowerCase() : '';
25-
let [direction, wrap] = value.split(' ');
25+
let [direction, wrap, inline ] = value.split(' ');
26+
27+
// First value must be the `flex-direction`
2628
if (!LAYOUT_VALUES.find(x => x === direction)) {
2729
direction = LAYOUT_VALUES[0];
2830
}
29-
return [direction, validateWrapValue(wrap)];
31+
32+
if ( wrap == INLINE ) {
33+
wrap = ( inline != INLINE ) ? inline : null;
34+
inline = INLINE;
35+
}
36+
37+
return [direction, validateWrapValue(wrap), !!inline];
3038
}
3139

3240
/**
@@ -65,8 +73,6 @@ export function validateWrapValue(value) {
6573
return value;
6674
}
6775

68-
69-
7076
/**
7177
* Build the CSS that should be assigned to the element instance
7278
* BUG:
@@ -76,9 +82,9 @@ export function validateWrapValue(value) {
7682
* This way any padding or border specified on the child elements are
7783
* laid out and drawn inside that element's specified width and height.
7884
*/
79-
function buildCSS(direction, wrap = null) {
85+
function buildCSS(direction, wrap = null, inline = false) {
8086
return {
81-
'display': 'flex',
87+
'display': inline ? 'inline-flex' : 'flex',
8288
'box-sizing': 'border-box',
8389
'flex-direction': direction,
8490
'flex-wrap': !!wrap ? wrap : null

0 commit comments

Comments
 (0)