Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fxLayoutAlign): support flex-start and flex-end options #239

Merged
merged 1 commit into from
Mar 29, 2017
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
21 changes: 15 additions & 6 deletions src/lib/flexbox/api/layout-align.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ describe('layout-align directive', () => {
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
);
});
it('should add correct styles for `fxLayoutAlign="flex-start"` usage', () => {
expectDOMFrom(`<div fxLayoutAlign="flex-start"></div>`).toHaveCssStyle(
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
);
});
it('should add correct styles for `fxLayoutAlign="center"` usage', () => {
expectDOMFrom(`<div fxLayoutAlign="center"></div>`).toHaveCssStyle(
extendObject({'justify-content': 'center'}, CROSSAXIS_DEFAULTS)
Expand All @@ -102,6 +107,11 @@ describe('layout-align directive', () => {
extendObject({'justify-content': 'flex-end'}, CROSSAXIS_DEFAULTS)
);
});
it('should add correct styles for `fxLayoutAlign="flex-end"` usage', () => {
expectDOMFrom(`<div fxLayoutAlign="flex-end"></div>`).toHaveCssStyle(
extendObject({'justify-content': 'flex-end'}, CROSSAXIS_DEFAULTS)
);
});
it('should add ignore invalid main-axis values', () => {
expectDOMFrom(`<div fxLayoutAlign="invalid"></div>`).toHaveCssStyle(
extendObject({'justify-content': 'flex-start'}, CROSSAXIS_DEFAULTS)
Expand All @@ -119,12 +129,11 @@ describe('layout-align directive', () => {
);
});
it('should add correct styles for `fxLayoutAlign="start baseline"` usage', () => {
expectDOMFrom(`<div fxLayoutAlign="start baseline"></div>`).toHaveCssStyle(
extendObject(MAINAXIS_DEFAULTS, {
'align-items': 'baseline',
'align-content': 'stretch'
})
);
expectDOMFrom(`<div fxLayoutAlign="start baseline"></div>`)
.toHaveCssStyle({
'justify-content' : 'flex-start',
'align-items': 'baseline'
});
});
it('should add correct styles for `fxLayoutAlign="start center"` usage', () => {
expectDOMFrom(`<div fxLayoutAlign="start center"></div>`).toHaveCssStyle(
Expand Down
15 changes: 11 additions & 4 deletions src/lib/flexbox/api/layout-align.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
protected _buildCSS(align) {
let css = {}, [main_axis, cross_axis] = align.split(' '); // tslint:disable-line:variable-name

css['justify-content'] = 'flex-start'; // default main axis
css['align-items'] = 'stretch'; // default cross axis
css['align-content'] = 'stretch'; // default cross axis

// Main axis
switch (main_axis) {
case 'center':
Expand All @@ -157,12 +153,20 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
css['justify-content'] = 'space-between';
break;
case 'end':
case 'flex-end':
css['justify-content'] = 'flex-end';
break;
case 'start':
case 'flex-start':
default :
css['justify-content'] = 'flex-start'; // default main axis
break;
}

// Cross-axis
switch (cross_axis) {
case 'start':
case 'flex-start':
css['align-items'] = css['align-content'] = 'flex-start';
break;
case 'baseline':
Expand All @@ -172,9 +176,12 @@ export class LayoutAlignDirective extends BaseFxDirective implements OnInit, OnC
css['align-items'] = css['align-content'] = 'center';
break;
case 'end':
case 'flex-end':
css['align-items'] = css['align-content'] = 'flex-end';
break;
case 'stretch':
default : // 'stretch'
css['align-items'] = css['align-content'] = 'stretch'; // default cross axis
break;
}

Expand Down