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 icon is hidden when no tabs #10

Merged
merged 3 commits into from
Dec 21, 2021
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
8 changes: 4 additions & 4 deletions examples/tabs/demos/custom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export default {
panelData: [{
value: 'first',
label: '原有选项卡',
removable: false,
removable: true,
content: '原有选项卡内容',
}, {
value: 'second',
label: '原有选项卡',
removable: false,
removable: true,
content: '原有选项卡内容',
}],
};
Expand All @@ -59,8 +59,8 @@ export default {
const index = this.panelData.findIndex((data) => data.value === value);
if (index < 0) return false;
this.panelData.splice(index, 1);
if (this.value === value) {
this.value = this.panelData[index - 1].value;
if (this.value === value && this.panelData.length) {
this.value = this.panelData[Math.max(index - 1, 0)].value;
}
},
changeTab(value) {
Expand Down
5 changes: 4 additions & 1 deletion src/tabs/tab-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export default (Vue as VueConstructor<TabNavVue>).extend({
navBarClass(): Array<string> {
return [`${prefix}-tabs__bar`, `${prefix}-is-${this.placement}`];
},
navsContainerStyle(): object {
return this.addable ? { 'min-height': '48px' } : null;
},
},
watch: {
dataCanUpdateArrow() {
Expand Down Expand Up @@ -468,7 +471,7 @@ export default (Vue as VueConstructor<TabNavVue>).extend({
},
render() {
return (
<div ref="navsContainer" class={[`${prefix}-tabs__nav`]}>
<div ref="navsContainer" class={[`${prefix}-tabs__nav`]} style={this.navsContainerStyle}>
{this.renderArrows()}
{this.renderNavs()}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default (Vue as VueConstructor<TabVue>).extend({
return this.listPanels;
},
renderContent() {
this.listPanels = this.list ? this.renderList() : this.$scopedSlots.default?.({});
// default 的函数可能返回null,此时为了防止 panels 的更新失败,默认用空数组
this.listPanels = this.list ? this.renderList() : (this.$scopedSlots.default?.({}) || []);
return (
<div class={[`${prefix}-tabs__content`]}>
{ this.listPanels }
Expand Down
4 changes: 2 additions & 2 deletions test/ssr/__snapshots__/ssr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12929,7 +12929,7 @@ exports[`ssr snapshot test renders ./examples/tabs/demos/combination.vue correct
exports[`ssr snapshot test renders ./examples/tabs/demos/custom.vue correctly 1`] = `
<div class="t-tabs" style="width:100%;">
<div class="t-tabs__header t-is-top">
<div class="t-tabs__nav">
<div class="t-tabs__nav" style="min-height:48px;">
<div class="t-tabs__operations t-tabs__operations--left">
<div name="fade" mode="out-in" appear="true"></div>
</div>
Expand Down Expand Up @@ -12994,7 +12994,7 @@ exports[`ssr snapshot test renders ./examples/tabs/demos/icon.vue correctly 1`]
exports[`ssr snapshot test renders ./examples/tabs/demos/operation.vue correctly 1`] = `
<div class="t-tabs">
<div class="t-tabs__header t-is-top">
<div class="t-tabs__nav">
<div class="t-tabs__nav" style="min-height:48px;">
<div class="t-tabs__operations t-tabs__operations--left">
<div name="fade" mode="out-in" appear="true"></div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions test/unit/tabs/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ exports[`Tabs custom demo works fine 1`] = `
>
<div
class="t-tabs__nav"
style="min-height: 48px;"
>
<div
class="t-tabs__operations t-tabs__operations--left"
Expand Down Expand Up @@ -602,6 +603,7 @@ exports[`Tabs operation demo works fine 1`] = `
>
<div
class="t-tabs__nav"
style="min-height: 48px;"
>
<div
class="t-tabs__operations t-tabs__operations--left"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tabs/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Tabs :props :addable 1`] = `
<div class="t-tabs">
<div class="t-tabs__header t-is-top">
<div class="t-tabs__nav">
<div class="t-tabs__nav" style="min-height: 48px;">
<div class="t-tabs__operations t-tabs__operations--left">
<transition-stub name="fade" appear="true" mode="out-in"></transition-stub>
</div>
Expand Down