Skip to content

Commit 7a1f814

Browse files
author
sunxiaoyu
committed
add tabs slot 功能
1 parent 8bb7f1b commit 7a1f814

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/tabs/docs/basic.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<s-tabpane tab="Tab 1" key="1">Content of Tab Pane 1</s-tabpane>
1414
<s-tabpane tab="Tab 2" key="2">Content of Tab Pane 2</s-tabpane>
1515
<s-tabpane tab="Tab 3" key="3">Content of Tab Pane 3</s-tabpane>
16+
<s-tabpane tab="Tab 4" key="4"><span slot="tab">Tab 4</span>Content of Tab Pane 4</s-tabpane>
1617
</s-tabs>
1718
</div>
1819
</template>

src/tabs/tabBarTabsNode.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@ export default san.defineComponent({
2323
let tabBarData = this.data.get('tabBarData') || [];
2424
const tabBarGutter = this.data.get('tabBarGutter');
2525
const tabBarPosition = this.data.get('tabBarPosition');
26+
const tabPanes = this.data.get('tabPanes') || [];
2627

2728
return tabBarData.map((tabBar, index) => {
2829
const gutter = tabBarGutter && index === tabBarData.length - 1 ? 0 : tabBarGutter;
2930
const style = gutter !== undefined && {[isVertical(tabBarPosition) ? 'margin-bottom' : 'margin-right']: gutter + 'px'};
3031
let classArr = [`${prefixCls}-tab`];
32+
// 获取parent节点
33+
let slot = tabPanes[index] && tabPanes[index].sourceSlots.named.tab || null;
34+
3135
tabBar.active && classArr.push(`${prefixCls}-tab-active`);
3236
tabBar.disabled && classArr.push(`${prefixCls}-tab-disabled`);
3337

3438
return {
3539
...tabBar,
40+
slot,
3641
classes: classArr,
3742
style: style
3843
};
3944
});
40-
},
41-
slots() {
42-
const tabPanes = this.data.get('tabPanes') || [];
43-
return tabPanes.map(pane => pane.sourceSlots.named.tab).filter(pane => pane);
4445
}
4546
},
4647
handleTabClick(e, key, disabled) {
@@ -77,8 +78,8 @@ export default san.defineComponent({
7778
on-click="handleTabClick($event, tabBar.key, tabBar.disabled)"
7879
>
7980
<div class="{{tabBar.closable ? '${prefixCls}-tab-uncloseable' : ''}}" s-if="type === 'editable-card'">
80-
<template s-if="slots && slots.length">
81-
<s-customtab slot="{{slots[index]}}" />
81+
<template s-if="tabBar.slot">
82+
<s-customtab slot="{{tabBar.slot}}"/>
8283
</template>
8384
<template s-else>
8485
{{tabBar.tab}}
@@ -91,8 +92,8 @@ export default san.defineComponent({
9192
/>
9293
</div>
9394
<template s-else>
94-
<template s-if="slots && slots.length">
95-
<s-customtab slot="{{slots[index]}}" />
95+
<template s-if="tabBar.slot">
96+
<s-customtab slot="{{tabBar.slot}}" />
9697
</template>
9798
<template s-else>
9899
{{tabBar.tab}}

0 commit comments

Comments
 (0)