mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
feat(tabs): add selectedIndex property to tabs
This commit is contained in:
@ -46,8 +46,8 @@ import {isUndefined} from '../../util/util';
|
||||
'<ion-tabbar-section>' +
|
||||
'<tabbar role="tablist">' +
|
||||
'<a *ngFor="#t of _tabs" [tab]="t" class="tab-button" role="tab">' +
|
||||
'<ion-icon [name]="t.tabIcon" [isActive]="t.isSelected" class="tab-button-icon"></ion-icon>' +
|
||||
'<span class="tab-button-text">{{t.tabTitle}}</span>' +
|
||||
'<ion-icon *ngIf="t.tabIcon" [name]="t.tabIcon" [isActive]="t.isSelected" class="tab-button-icon"></ion-icon>' +
|
||||
'<span *ngIf="t.tabTitle" class="tab-button-text">{{t.tabTitle}}</span>' +
|
||||
'<ion-badge *ngIf="t.tabBadge" class="tab-badge" [ngClass]="\'badge-\' + t.tabBadgeStyle">{{t.tabBadge}}</ion-badge>' +
|
||||
'</a>' +
|
||||
'<tab-highlight></tab-highlight>' +
|
||||
@ -75,6 +75,7 @@ export class Tabs extends Ion {
|
||||
navbarContainerRef: ViewContainerRef;
|
||||
subPages: boolean;
|
||||
|
||||
@Input() selectedIndex: any;
|
||||
@Input() preloadTabs: any;
|
||||
@Input() tabbarIcons: string;
|
||||
@Input() tabbarPlacement: string;
|
||||
@ -133,8 +134,10 @@ export class Tabs extends Ion {
|
||||
});
|
||||
});
|
||||
|
||||
let selectedIndex = this.selectedIndex ? parseInt(this.selectedIndex, 10) : 0;
|
||||
|
||||
this._tabs.forEach((tab, index) => {
|
||||
if (index === 0) {
|
||||
if (index === selectedIndex) {
|
||||
this.select(tab);
|
||||
|
||||
} else if (this.preloadTabs) {
|
||||
@ -206,10 +209,10 @@ export class Tabs extends Ion {
|
||||
this._tabs.forEach(tab => {
|
||||
tab.setSelected(tab === selectedTab);
|
||||
});
|
||||
}
|
||||
|
||||
if (this._useHighlight) {
|
||||
this._highlight.select(selectedTab);
|
||||
if (this._useHighlight) {
|
||||
this._highlight.select(selectedTab);
|
||||
}
|
||||
}
|
||||
|
||||
selectedPage && selectedPage.didEnter();
|
||||
|
@ -1,9 +1,17 @@
|
||||
import {App} from 'ionic/ionic';
|
||||
import {App, Page} from 'ionic/ionic';
|
||||
|
||||
|
||||
@Page({template:'hi'})
|
||||
class E2EPage{}
|
||||
|
||||
|
||||
@App({
|
||||
templateUrl: 'main.html'
|
||||
})
|
||||
class E2EApp {}
|
||||
class E2EApp {
|
||||
constructor() {
|
||||
this.root = E2EPage;
|
||||
}
|
||||
}
|
||||
|
||||
document.body.innerHTML += '<link href="styles.css" rel="stylesheet">'
|
||||
|
@ -1,71 +1,71 @@
|
||||
|
||||
<!-- Text -->
|
||||
<ion-tabs no-navbar>
|
||||
<ion-tab tabTitle="Recents"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites"></ion-tab>
|
||||
<ion-tab tabTitle="Settings"></ion-tab>
|
||||
<ion-tab tabTitle="Recents" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- Icons -->
|
||||
<ion-tabs no-navbar>
|
||||
<ion-tab tabIcon="call"></ion-tab>
|
||||
<ion-tab tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabIcon="settings"></ion-tab>
|
||||
<ion-tabs no-navbar selectedIndex="1">
|
||||
<ion-tab tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- Icons on top of text -->
|
||||
<ion-tabs no-navbar>
|
||||
<ion-tab tabTitle="Location" tabIcon="navigate"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="star"></ion-tab>
|
||||
<ion-tab tabTitle="Radio" tabIcon="musical-notes"></ion-tab>
|
||||
<ion-tabs no-navbar selectedIndex="2">
|
||||
<ion-tab tabTitle="Location" tabIcon="navigate" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="star" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Radio" tabIcon="musical-notes" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- Icons below text -->
|
||||
<ion-tabs tabbarIcons="bottom" no-navbar>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings"></ion-tab>
|
||||
<ion-tabs tabbarIcons="bottom" no-navbar selectedIndex="1">
|
||||
<ion-tab tabTitle="Recents" tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- Icons right of text -->
|
||||
<ion-tabs tabbarIcons="right" no-navbar>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings"></ion-tab>
|
||||
<ion-tabs tabbarIcons="right" no-navbar selectedIndex="0">
|
||||
<ion-tab tabTitle="Recents" tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- Icons left of text -->
|
||||
<ion-tabs tabbarIcons="left" no-navbar>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings"></ion-tab>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- No icons -->
|
||||
<ion-tabs tabbarIcons="hide" no-navbar>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings"></ion-tab>
|
||||
<ion-tab tabTitle="Recents" tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Favorites" tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Settings" tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- No overflow text -->
|
||||
<ion-tabs no-navbar>
|
||||
<ion-tab tabTitle="Indiana Jones and the Raiders of the Lost Ark"></ion-tab>
|
||||
<ion-tab tabTitle="Indiana Jones and the Temple of Doom"></ion-tab>
|
||||
<ion-tab tabTitle="Indiana Jones and the Last Crusade"></ion-tab>
|
||||
<ion-tab tabTitle="Indiana Jones and the Raiders of the Lost Ark" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Indiana Jones and the Temple of Doom" [root]="root"></ion-tab>
|
||||
<ion-tab tabTitle="Indiana Jones and the Last Crusade" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
||||
|
||||
<!-- primary color tabbar -->
|
||||
<ion-tabs no-navbar primary>
|
||||
<ion-tab tabIcon="call"></ion-tab>
|
||||
<ion-tab tabIcon="heart"></ion-tab>
|
||||
<ion-tab tabIcon="settings"></ion-tab>
|
||||
<ion-tab tabIcon="call" [root]="root"></ion-tab>
|
||||
<ion-tab tabIcon="heart" [root]="root"></ion-tab>
|
||||
<ion-tab tabIcon="settings" [root]="root"></ion-tab>
|
||||
</ion-tabs>
|
||||
|
Reference in New Issue
Block a user