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

feat(tabs): add the ability to invert the header #2391

Merged
merged 1 commit into from
Jan 18, 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
10 changes: 10 additions & 0 deletions src/demo-app/tabs/tabs-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,13 @@ <h1>Tabs with simplified api</h1>
This tab is about combustion!
</md-tab>
</md-tab-group>

<h1>Inverted tabs</h1>
<md-tab-group class="demo-tab-group" headerPosition="below">
<md-tab label="Earth">
This tab is about the Earth!
</md-tab>
<md-tab label="Fire">
This tab is about combustion!
</md-tab>
</md-tab-group>
5 changes: 5 additions & 0 deletions src/lib/tabs/_tabs-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ $md-tab-animation-duration: 500ms !default;
bottom: 0;
height: 2px;
transition: $md-tab-animation-duration $ease-in-out-curve-function;

.md-tab-group-inverted-header & {
bottom: auto;
top: 0;
}
}
13 changes: 9 additions & 4 deletions src/lib/tabs/_tabs-theme.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
@import '../core/theming/palette';
@import '../core/theming/theming';


@mixin md-tabs-theme($theme) {
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$warn: map-get($theme, warn);
$background: map-get($theme, background);
$foreground: map-get($theme, foreground);
$header-border: 1px solid md-color($background, status-bar);

[md-tab-nav-bar],
.md-tab-header {
border-bottom: 1px solid md-color($background, status-bar);
border-bottom: $header-border;

.md-tab-group-inverted-header & {
border-top: $header-border;
border-bottom: none;
}
}

.md-tab-label:focus {
background-color: md-color($primary, 100, 0.3);
}

md-ink-bar {
background-color: md-color($primary, 500);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/tabs/tab-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
display: flex;
flex-direction: column;
font-family: $md-font-family;

&.md-tab-group-inverted-header {
flex-direction: column-reverse;
}
}

// Wraps each tab label
Expand Down
15 changes: 14 additions & 1 deletion src/lib/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
async, fakeAsync, tick, ComponentFixture, TestBed
} from '@angular/core/testing';
import {MdTabGroup, MdTabsModule} from './tab-group';
import {MdTabGroup, MdTabsModule, MdTabHeaderPosition} from './tab-group';
import {Component, ViewChild} from '@angular/core';
import {By} from '@angular/platform-browser';
import {Observable} from 'rxjs/Observable';
Expand Down Expand Up @@ -238,6 +238,17 @@ describe('MdTabGroup', () => {
it('should support @ViewChild in the tab content', () => {
expect(fixture.componentInstance.legumes).toBeTruthy();
});

it('should support setting the header position', () => {
let tabGroupNode = fixture.debugElement.query(By.css('md-tab-group')).nativeElement;

expect(tabGroupNode.classList).not.toContain('md-tab-group-inverted-header');

tabGroup.headerPosition = 'below';
fixture.detectChanges();

expect(tabGroupNode.classList).toContain('md-tab-group-inverted-header');
});
});

/**
Expand Down Expand Up @@ -273,6 +284,7 @@ describe('MdTabGroup', () => {
template: `
<md-tab-group class="tab-group"
[(selectedIndex)]="selectedIndex"
[headerPosition]="headerPosition"
(focusChange)="handleFocus($event)"
(selectChange)="handleSelection($event)">
<md-tab>
Expand All @@ -294,6 +306,7 @@ class SimpleTabsTestApp {
selectedIndex: number = 1;
focusEvent: any;
selectEvent: any;
headerPosition: MdTabHeaderPosition = 'above';
handleFocus(event: any) {
this.focusEvent = event;
}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class MdTabChangeEvent {
tab: MdTab;
}

/** Possible positions for the tab header. */
export type MdTabHeaderPosition = 'above' | 'below';

/**
* Material design tab-group component. Supports basic tab pairs (label + content) and includes
* animated ink-bar, keyboard navigation, and screen reader.
Expand All @@ -49,7 +52,10 @@ export class MdTabChangeEvent {
selector: 'md-tab-group',
templateUrl: 'tab-group.html',
styleUrls: ['tab-group.css'],
host: { '[class.md-tab-group-dynamic-height]': 'dynamicHeight' }
host: {
'[class.md-tab-group-dynamic-height]': 'dynamicHeight',
'[class.md-tab-group-inverted-header]': 'headerPosition === "below"',
}
})
export class MdTabGroup {
@ContentChildren(MdTab) _tabs: QueryList<MdTab>;
Expand Down Expand Up @@ -83,6 +89,10 @@ export class MdTabGroup {
set selectedIndex(value: number) { this._indexToSelect = value; }
get selectedIndex(): number { return this._selectedIndex; }

/** Position of the tab header. */
@Input()
headerPosition: MdTabHeaderPosition = 'above';

/** Output to enable support for two-way binding on `selectedIndex`. */
@Output() get selectedIndexChange(): Observable<number> {
return this.selectChange.map(event => event.index);
Expand Down