Skip to content

feat(tabs): add header-only #3638

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions examples/sites/demos/apis/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ export default {
mode: ['pc', 'mobile-first'],
pcDemo: 'overflow-title',
mfDemo: ''
},
{
name: 'header-only',
type: 'boolean',
defaultValue: 'false',
desc: {
'zh-CN': '当 header-only 为 true 时,页签内容不再渲染,并且 position 将被设置为固定值 top',
Copy link
Collaborator

@chenxi-20 chenxi-20 Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议描述更改为:当 header-only 为 true 时,页签内容不再渲染;此时position 值只能为 top

但更好的方式应该是支持所有的position值,只有top不太合理

@liangguanhui0117

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我把所有position模式,都支持下

'en-US': 'When header-only is true, the tab content will no longer be rendered, and the position will be set to a fixed value of top'
},
mode: ['pc'],
pcDemo: 'header-only',
mfDemo: ''
}
],
events: [
Expand Down
36 changes: 36 additions & 0 deletions examples/sites/demos/pc/app/tabs/header-only.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<tiny-tabs tab-style="card" style="width: 500px" :position="position" header-only>
<tiny-tab-item :key="item.name" v-for="item in tabs" :title="item.title" :name="item.name">
{{ item.content }}
</tiny-tab-item>
</tiny-tabs>
</template>

<script lang="jsx">
import { TinyTabs, TinyTabItem } from '@opentiny/vue'

export default {
components: {
TinyTabs,
TinyTabItem
},
data() {
return {
position: 'left',
tabs: [
{
title: 'Tab 1',
name: '1',
content: 'Tab 1 content '
},
{
title: 'Tab 2',
name: '2',
content: 'Tab 2 content'
}
],
tabIndex: 2
}
}
}
</script>
12 changes: 12 additions & 0 deletions examples/sites/demos/pc/app/tabs/webdoc/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,18 @@ export default {
'Use <code>overflow-title</code> to set the title to hide and show when it exceeds a certain length (default 256px)... , move the cursor to the title to display the tooltip, and set <code>title-width</code> to the excess length of the title.'
},
codeFiles: ['overflow-title.vue']
},
{
demoId: 'header-only',
name: {
'zh-CN': '仅展示头部',
'en-US': 'Header only'
},
desc: {
'zh-CN': '通过 <code>header-only</code> 仅展示头部。',
'en-US': 'Use <code>>header-only</code> header only.'
},
codeFiles: ['header-only.vue']
}
],
features: [
Expand Down
3 changes: 2 additions & 1 deletion packages/renderless/src/tabs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const initState = ({ reactive, props }: Pick<ITabsRenderlessParams, 'reactive' |
direction: '',
expandPanesWidth: '',
activeIndex: 1,
separator: props.separator
separator: props.separator,
headerOnly: props.headerOnly
}) as ITabsState

const initWatcher = ({
Expand Down
1 change: 1 addition & 0 deletions packages/renderless/types/tabs.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ITabsState {
activeIndex: number
morePanes?: ITabsPaneVm[]
separator?: boolean
headerOnly?: boolean
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/tab-item/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-->
<template>
<div
v-if="!lazy || state.loaded || state.active"
v-if="!state.rootTabs.headerOnly && (!lazy || state.loaded || state.active)"
v-show="state.active"
:aria-hidden="!state.active"
:id="`pane-${state.paneName}`"
Expand Down
4 changes: 3 additions & 1 deletion packages/vue/src/tabs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export const tabsProps = {
// tiny 新增
moreShowAll: Boolean,
panelMaxHeight: String,
panelWidth: String
panelWidth: String,
// 只渲染头部
headerOnly: Boolean
}

export default defineComponent({
Expand Down
11 changes: 7 additions & 4 deletions packages/vue/src/tabs/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default defineComponent({
'titleWidth',
'moreShowAll',
'panelMaxHeight',
'panelWidth'
'panelWidth',
'headerOnly'
],
components: {
TabNav,
Expand All @@ -78,7 +79,6 @@ export default defineComponent({
handleTabDragEnd,
editable,
withAdd,
position,
size,
stretch,
showMoreTabs,
Expand All @@ -89,9 +89,12 @@ export default defineComponent({
overflowTitle,
titleWidth,
panelMaxHeight,
panelWidth
panelWidth,
headerOnly
} = this

const position = headerOnly ? 'top' : this.position

const newButton =
editable || withAdd ? (
<span
Expand Down Expand Up @@ -150,7 +153,7 @@ export default defineComponent({
</div>
)

const panels = <div class="tiny-tabs__content">{this.slots.default && this.slots.default()}</div>
const panels = headerOnly ? this.slots.default?.() : <div class="tiny-tabs__content">{this.slots.default?.()}</div>

return (
<div
Expand Down