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

Commit eb5cb9f

Browse files
ThomasBurlesontinayuangao
authored andcommitted
fix(fxLayoutAlign): support flex-start and flex-end options (#239)
Current API translates `start` and `end` to `flex-start` and `flex-end` respectively. The API should also support the raw flex-<xxx> values. Fixes #232.
1 parent 5db01e7 commit eb5cb9f

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ describe('layout-align directive', () => {
8282
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
8383
);
8484
});
85+
it('should add correct styles for `fxLayoutAlign="flex-start"` usage', () => {
86+
expectDOMFrom(`<div fxLayoutAlign="flex-start"></div>`).toHaveCssStyle(
87+
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
88+
);
89+
});
8590
it('should add correct styles for `fxLayoutAlign="center"` usage', () => {
8691
expectDOMFrom(`<div fxLayoutAlign="center"></div>`).toHaveCssStyle(
8792
extendObject({'justify-content': 'center'}, CROSSAXIS_DEFAULTS)
@@ -102,6 +107,11 @@ describe('layout-align directive', () => {
102107
extendObject({'justify-content': 'flex-end'}, CROSSAXIS_DEFAULTS)
103108
);
104109
});
110+
it('should add correct styles for `fxLayoutAlign="flex-end"` usage', () => {
111+
expectDOMFrom(`<div fxLayoutAlign="flex-end"></div>`).toHaveCssStyle(
112+
extendObject({'justify-content': 'flex-end'}, CROSSAXIS_DEFAULTS)
113+
);
114+
});
105115
it('should add ignore invalid main-axis values', () => {
106116
expectDOMFrom(`<div fxLayoutAlign="invalid"></div>`).toHaveCssStyle(
107117
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
@@ -119,12 +129,11 @@ describe('layout-align directive', () => {
119129
);
120130
});
121131
it('should add correct styles for `fxLayoutAlign="start baseline"` usage', () => {
122-
expectDOMFrom(`<div fxLayoutAlign="start baseline"></div>`).toHaveCssStyle(
123-
extendObject(MAINAXIS_DEFAULTS, {
124-
'align-items': 'baseline',
125-
'align-content': 'stretch'
126-
})
127-
);
132+
expectDOMFrom(`<div fxLayoutAlign="start baseline"></div>`)
133+
.toHaveCssStyle({
134+
'justify-content' : 'flex-start',
135+
'align-items': 'baseline'
136+
});
128137
});
129138
it('should add correct styles for `fxLayoutAlign="start center"` usage', () => {
130139
expectDOMFrom(`<div fxLayoutAlign="start center"></div>`).toHaveCssStyle(

src/lib/flexbox/api/layout-align.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
141141
protected _buildCSS(align) {
142142
let css = {}, [main_axis, cross_axis] = align.split(' '); // tslint:disable-line:variable-name
143143

144-
css['justify-content'] = 'flex-start'; // default main axis
145-
css['align-items'] = 'stretch'; // default cross axis
146-
css['align-content'] = 'stretch'; // default cross axis
147-
148144
// Main axis
149145
switch (main_axis) {
150146
case 'center':
@@ -157,12 +153,20 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
157153
css['justify-content'] = 'space-between';
158154
break;
159155
case 'end':
156+
case 'flex-end':
160157
css['justify-content'] = 'flex-end';
161158
break;
159+
case 'start':
160+
case 'flex-start':
161+
default :
162+
css['justify-content'] = 'flex-start'; // default main axis
163+
break;
162164
}
165+
163166
// Cross-axis
164167
switch (cross_axis) {
165168
case 'start':
169+
case 'flex-start':
166170
css['align-items'] = css['align-content'] = 'flex-start';
167171
break;
168172
case 'baseline':
@@ -172,9 +176,12 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
172176
css['align-items'] = css['align-content'] = 'center';
173177
break;
174178
case 'end':
179+
case 'flex-end':
175180
css['align-items'] = css['align-content'] = 'flex-end';
176181
break;
182+
case 'stretch':
177183
default : // 'stretch'
184+
css['align-items'] = css['align-content'] = 'stretch'; // default cross axis
178185
break;
179186
}
180187

0 commit comments

Comments
 (0)