Skip to content

Commit 8efa172

Browse files
committed
fix change tab path functionality
1 parent bc07fcb commit 8efa172

File tree

9 files changed

+65
-8
lines changed

9 files changed

+65
-8
lines changed

demo/src/demo/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Numeric } from './numeric';
1111
import { Currency } from './currency';
1212
import { TabBasic } from './tab/basic';
1313
import { TabInteractive } from './tab/interactive';
14+
import { TabPath } from './tab/path';
1415
import { Button } from './button';
1516
import { Radio } from './radio';
1617
import { Checkbox } from './checkbox';
@@ -49,6 +50,7 @@ const m = [
4950
{ group: 'component/datetime', text: 'DateTime', path: 'datetime', component: DateTime },
5051
{ group: 'component/tab', text: 'Tab', path: 'tab/basic', component: TabBasic },
5152
{ group: 'component/tab', text: 'Tab Interactive', path: 'tab/interactive', component: TabInteractive },
53+
{ group: 'component/tab', text: 'Tab Path', path: 'tab/path', component: TabPath },
5254
{ group: 'component/button', text: 'Buttons', path: 'button', component: Button },
5355
{ group: 'component/radio', text: 'Radio', path: 'radio', component: Radio },
5456
{ group: 'component/checkbox', text: 'Checkbox', path: 'checkbox', component: Checkbox },

demo/src/demo/tab/path/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div>
2+
3+
<ui-tab id="tab-path-example">
4+
<ui-tab-item caption="Tab 1" path="one">Contents of Tab 1</ui-tab-item>
5+
<ui-tab-item caption="Tab 2" path="two">Contents of Tab 2</ui-tab-item>
6+
<ui-tab-item caption="Tab 3" path="three">Contents of Tab 3</ui-tab-item>
7+
</ui-tab>
8+
9+
<ui-button @click="tab1">Tab 1</ui-button> <ui-button @click="tab2">Tab 2</ui-button> <ui-button @click="tab3">Tab 3</ui-button>
10+
11+
</div>

demo/src/demo/tab/path/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from 'vue-typed';
2+
import { Base } from '../../base'
3+
import * as Vue from 'vue'
4+
5+
@Component({
6+
template: require('./index.html')
7+
})
8+
export class TabPath extends Base {
9+
tab1() {
10+
this.$ui.tab('#tab-path-example').changeTab('one')
11+
}
12+
tab2() {
13+
this.$ui.tab('#tab-path-example').changeTab('two')
14+
}
15+
tab3() {
16+
this.$ui.tab('#tab-path-example').changeTab('three')
17+
}
18+
}

dist/vue-typed-ui.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,13 +1852,13 @@ var Tab = function (_TabBase2) {
18521852
var _this = possibleConstructorReturn(this, (Tab.__proto__ || Object.getPrototypeOf(Tab)).apply(this, arguments));
18531853

18541854
_this.items = [];
1855+
_this.firstTab = undefined;
18551856
return _this;
18561857
}
18571858

18581859
createClass(Tab, [{
18591860
key: 'created',
18601861
value: function created() {
1861-
this.activeTab = this._tabName(1);
18621862
this.items = [];
18631863
this.updateStyle();
18641864
}
@@ -1868,6 +1868,7 @@ var Tab = function (_TabBase2) {
18681868
var _this2 = this;
18691869

18701870
Vue.nextTick(function () {
1871+
_this2.activeTab = _this2.firstTab;
18711872
_this2._suiInit();
18721873
});
18731874
}
@@ -1885,7 +1886,8 @@ var Tab = function (_TabBase2) {
18851886
key: 'createItem',
18861887
value: function createItem(item) {
18871888
this.items.push(item);
1888-
var tabName = this._tabName(this.items.length);
1889+
var tabName = item.path || this._tabName(this.items.length);
1890+
if (!this.firstTab) this.firstTab = tabName;
18891891
if (item.active == true) {
18901892
this.activeTab = tabName;
18911893
}
@@ -1955,6 +1957,9 @@ __decorate([vueTyped.Prop({
19551957
__decorate([vueTyped.Prop({
19561958
type: Boolean
19571959
})], _TabItemBase.prototype, "active", void 0);
1960+
__decorate([vueTyped.Prop({
1961+
type: String
1962+
})], _TabItemBase.prototype, "path", void 0);
19581963

19591964
var TabItem = function (_TabItemBase2) {
19601965
inherits(TabItem, _TabItemBase2);
@@ -3039,7 +3044,7 @@ function tab(instance, $this) {
30393044
return function (element) {
30403045
return {
30413046
changeTab: function changeTab(path) {
3042-
return $(element).tab('change tab', path);
3047+
return $(element).find('.item').tab('change tab', path);
30433048
}
30443049
};
30453050
};

doc/api.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,10 @@
10391039
"caption": {
10401040
"type": "string",
10411041
"description": "Tab caption"
1042+
},
1043+
"path": {
1044+
"type": "string",
1045+
"description": "Name of path"
10421046
}
10431047
},
10441048
"methods": {}

src/components/containers/tab-item/_base.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@ export abstract class _TabItemBase extends Vue {
2828
})
2929
active: boolean
3030

31+
/**
32+
* Name of path
33+
*
34+
* @type {string}
35+
*/
36+
@Prop({
37+
type: String
38+
})
39+
path: string
40+
3141
}

src/components/containers/tab-item/schema/props.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
"caption": {
77
"type": "string",
88
"description": "Tab caption"
9-
},
9+
},
1010
"active": {
1111
"type": "boolean",
1212
"description": "Set tab to active"
13+
},
14+
"path": {
15+
"type": "string",
16+
"description": "Name of path"
1317
}
1418
}
1519
}

src/components/containers/tab/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export class Tab extends _TabBase {
2121

2222
items: any[] = []
2323

24-
created() {
25-
this.activeTab = this._tabName(1);
24+
created() {
2625
this.items = [];
2726
this.updateStyle();
2827
}
2928

3029
mounted() {
3130

3231
Vue.nextTick(() => {
32+
this.activeTab = this.firstTab;
3333
this._suiInit();
3434
})
3535
}
@@ -43,10 +43,13 @@ export class Tab extends _TabBase {
4343

4444
}
4545

46+
firstTab = undefined
47+
4648
createItem(item): string {
4749

4850
this.items.push(item);
49-
var tabName = this._tabName(this.items.length);
51+
let tabName = item.path || this._tabName(this.items.length);
52+
if (!this.firstTab) this.firstTab = tabName
5053

5154
if (item.active == true) {
5255
this.activeTab = tabName;

src/components/containers/tab/methods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Tab } from '../../../../lib/methods'
44
export function tab(instance, $this: Vue) {
55
return function (element: string | HTMLElement | JQuery): Tab {
66
return {
7-
changeTab(path: string) { return $(element).tab('change tab', path); }
7+
changeTab(path: string) { return $(element).find('.item').tab('change tab', path); }
88
}
99
}
1010
}

0 commit comments

Comments
 (0)