Skip to content

Sidebar

Vertically displayed navigation bar, used to switch between different content areas.

Component Types

Basic Usage

Bind the current selected item's value through v-model.

html
<wd-sidebar v-model="active">
  <wd-sidebar-item :value="0" label="Tag Name" />
  <wd-sidebar-item :value="1" label="Tag Name" />
  <wd-sidebar-item :value="2" label="Tag Name" />
</wd-sidebar>
ts
const active = ref(0)

Component States

Badge Tips

Set is-dot to display a dot badge; set badge or badge-props to display a numeric badge.

html
<wd-sidebar v-model="active">
  <wd-sidebar-item :value="0" label="Tag Name" is-dot />
  <wd-sidebar-item :value="1" label="Tag Name" badge="5" />
  <wd-sidebar-item :value="2" label="Tag Name" :badge-props="{ type: 'warning', value: 55, max: 99 }" />
</wd-sidebar>

Disabled and Async Switching

Set disabled to disable the current option; set before-change to execute synchronous or asynchronous logic before switching.

html
<wd-sidebar v-model="active" :before-change="beforeChange">
  <wd-sidebar-item :value="0" label="Tag Name" />
  <wd-sidebar-item :value="1" label="Tag Name" disabled />
  <wd-sidebar-item :value="2" label="Tag Name" />
</wd-sidebar>
ts
import type { SidebarBeforeChange } from '@/uni_modules/wot-ui/components/wd-sidebar/types'

const beforeChange: SidebarBeforeChange = (value) => {
  return new Promise((resolve) => {
    setTimeout(() => resolve(true), 2000)
  })
}

Special Styles

Anchor Usage Example

Sidebar can be combined with scroll-view to achieve anchor switching for long content pages. Examples in the repository can be found in src/subPages/sidebar/demo1.vue.

Page Switching Usage Example

Sidebar can also be used as a left-side directory, with the right content area switching full-screen based on the current selected item. Examples in the repository can be found in src/subPages/sidebar/demo2.vue.

Custom Icon Example

Set the icon property of wd-sidebar-item to display different icons in the navigation item. Examples in the repository can be found in src/subPages/sidebar/demo3.vue.

ParameterDescriptionTypeDefault Value
model-value / v-modelCurrent active item's valuestring | number0
before-change v1.4.0Hook before switching, receives target value, returns boolean or Promise<boolean>function-
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''
Event NameDescriptionParameters
changeTriggered when active item switches{ value, label }
NameDescription
defaultSidebarItem list
Class NameDescription
custom-classRoot node style

SidebarItem Attributes

ParameterDescriptionTypeDefault Value
labelCurrent option titlestring-
valueCurrent option value, unique identifierstring | number-
badgeBadge display valuestring | number-
badge-props ^(0.1.50)Custom badge properties, will be passed to Badge componentPartial<BadgeProps>-
iconIcon namestring-
is-dotWhether to display dot badgebooleanfalse
maxBadge maximum valuenumber99
disabledWhether to disable the current optionbooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

SidebarItem Slots

NameDescription
iconCustom icon content

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-sidebar-width114px侧边栏宽度
--wot-sidebar-height100%侧边栏高度
--wot-sidebar-bg$filled-oppo侧边栏背景色
--wot-sidebar-padding-bg$filled-oppo内容区背景色
--wot-sidebar-item-font-size$typography-body-size-main选项字号
--wot-sidebar-item-line-height$typography-body-line--height-size-main选项行高
--wot-sidebar-item-color$text-main选项文字颜色
--wot-sidebar-item-padding$padding-extra-tight $padding-extra-loose选项内边距
--wot-sidebar-item-bg$filled-bottom选项背景色
--wot-sidebar-item-min-height$n-52选项最小高度
--wot-sidebar-item-bg-hover$feedback-active选项点击态背景色
--wot-sidebar-item-bg-active$filled-oppo激活项背景色
--wot-sidebar-item-color-active$primary-6激活项文字颜色
--wot-sidebar-item-font-weight-active$font-weight-semibold激活项字重
--wot-sidebar-item-indicator-width$n-2激活指示条宽度
--wot-sidebar-item-indicator-height$n-20激活指示条高度
--wot-sidebar-item-border-radius$radius-large圆角大小
--wot-sidebar-item-color-disabled$text-disabled禁用状态文字颜色
--wot-sidebar-item-icon-size$n-20图标大小
--wot-sidebar-item-icon-margin-right$padding-ultra-tight图标右边距

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.