support tab title renter funtion

pull/1486/merge
baiyaaaaa 2016-11-18 15:41:08 +08:00 committed by 杨奕
parent 568df8058d
commit 34dbb01c1a
6 changed files with 28 additions and 7 deletions

View File

@ -142,4 +142,5 @@ Border card tabs.
| Attribute | Description | Type | Accepted Values | Default | | Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- | |---------- |-------- |---------- |------------- |-------- |
| label | title of the tab | string | — | — | | label | title of the tab | string | — | — |
| label-content | render function for tab title | Function(h) | - | - |
| name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' | | name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' |

View File

@ -137,4 +137,5 @@
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------- |---------- |------------- |-------- | |---------- |-------- |---------- |------------- |-------- |
| label | 选项卡标题 | string | — | — | | label | 选项卡标题 | string | — | — |
| label-content | 选项卡的标题的渲染 Function | Function(h) | - | - |
| name | 与选项卡 activeName 对应的标识符,表示选项卡别名 | string | — | 该选项卡在选项卡列表中的顺序值,如第一个选项卡则为'1' | | name | 与选项卡 activeName 对应的标识符,表示选项卡别名 | string | — | 该选项卡在选项卡列表中的顺序值,如第一个选项卡则为'1' |

View File

@ -3,10 +3,8 @@
name: 'el-tab-pane', name: 'el-tab-pane',
props: { props: {
label: { label: String,
type: String, labelContent: Function,
required: true
},
name: String, name: String,
closable: Boolean closable: Boolean
}, },

View File

@ -91,7 +91,7 @@
const activeBar = !type const activeBar = !type
? <div class="el-tabs__active-bar" style={barStyle}></div> ? <div class="el-tabs__active-bar" style={barStyle}></div>
: null; : null;
const tabs = this.$children.map((tab, index) => { const tabs = this.$children.map((tab, index) => {
let btnClose = h('span', { let btnClose = h('span', {
class: { class: {
@ -110,7 +110,7 @@
refInFor: true, refInFor: true,
on: { click: (ev) => { handleTabClick(tab, ev); } } on: { click: (ev) => { handleTabClick(tab, ev); } }
}, [ }, [
tab.label, tab.labelContent ? tab.labelContent.call(this._renderProxy, h) : tab.label,
tab.isClosable ? btnClose : null, tab.isClosable ? btnClose : null,
index === 0 ? activeBar : null index === 0 ? activeBar : null
]); ]);

View File

@ -4,7 +4,7 @@ Function.prototype.bind = require('function-bind');
require('packages/theme-default/src/index.css'); require('packages/theme-default/src/index.css');
// require all test files (files that ends with .spec.js) // require all test files (files that ends with .spec.js)
const testsContext = require.context('./specs', true, /\.spec$/); const testsContext = require.context('./specs', true, /tabs\.spec$/);
testsContext.keys().forEach(testsContext); testsContext.keys().forEach(testsContext);
// require all src files except main.js for coverage. // require all src files except main.js for coverage.

View File

@ -220,4 +220,25 @@ describe('Tabs', () => {
}); });
}, 100); }, 100);
}); });
it('tab title render function', done => {
vm = createVue({
template: `
<el-tabs ref="tabs" >
<el-tab-pane :label-content="renderTitle">A</el-tab-pane>
<el-tab-pane label="配置管理">B</el-tab-pane>
<el-tab-pane label="角色管理" ref="pane-click">C</el-tab-pane>
<el-tab-pane label="定时任务补偿">D</el-tab-pane>
</el-tabs>
`,
methods: {
renderTitle(h) {
return <span>用户管理</span>;
}
}
}, true);
vm.$nextTick(_ => {
expect(vm.$el.querySelector('.el-tabs__item span').innerText).to.equal('用户管理');
done();
});
});
}); });