Skip to content

Subsection ​

17:06

Description ​

Single choice from a set of options, in two shapes chosen by mode: button (default) shows a light track with a sliding button that moves between options, while subsection separates options with borders and fills the selected cell with active-color. current is the selected index (0-based); switching emits change(index).

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported (re-measures slider width and position on window resize)
WeChat Mini Program✅ Supported

Examples ​

Button Mode ​

Default button mode; slider moves between buttons.

View source
vue
<template>
    <ux-subsection :list="list" :current="current" @change="onChange"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'Tab1' },
    { name: 'Tab2' },
    { name: 'Tab3' }
];

const current = ref<number>(0);

function onChange(index: number): void {
    current.value = index;
}
</script>

Subsection Mode ​

mode=subsection for segmented mode with borders between options.

View source
vue
<template>
    <ux-subsection :list="list" :current="current" mode="subsection" @change="onChange"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'Tab1' },
    { name: 'Tab2' },
    { name: 'Tab3' }
];

const current = ref<number>(0);

function onChange(index: number): void {
    current.value = index;
}
</script>

Custom Colors ​

Customize active and inactive colors via active-color and inactive-color.

View source
vue
<template>
    <ux-subsection :list="list" :current="current" active-color="#fa3534" inactive-color="#909399"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'A' },
    { name: 'B' },
    { name: 'C' },
    { name: 'D' }
];

const current = ref<number>(1);
</script>

No Animation ​

animation=false disables slider animation.

View source
vue
<template>
    <ux-subsection :list="list" :current="current" :animation="false" @change="onChange"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'Tab1' },
    { name: 'Tab2' },
    { name: 'Tab3' }
];

const current = ref<number>(0);

function onChange(index: number): void {
    current.value = index;
}
</script>

Custom Style ​

Combine font-size, height, bg-color, button-color for custom appearance.

View source
vue
<template>
    <ux-subsection :list="list" :current="current" :font-size="12" :height="30" bg-color="#ecf5ff" button-color="#2979ff" active-color="#ffffff" inactive-color="#2979ff"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'Day' },
    { name: 'Week' },
    { name: 'Month' }
];

const current = ref<number>(0);
</script>

Disabled State ​

Set disabled=true to disable the whole component; a single item with disabled:true becomes unclickable.

View source
vue
<template>
    <ux-subsection :list="list" disabled></ux-subsection>
    <view class="gap"></view>
    <ux-subsection :list="list2" active-color="#fa3534" inactive-color="#909399"></ux-subsection>
</template>

<script setup lang="uts">
import type { SubsectionListItem } from '@/uni_modules/uview-pro-x';

const list: SubsectionListItem[] = [
    { name: 'Tab1' },
    { name: 'Tab2' },
    { name: 'Tab3' }
];

const list2: SubsectionListItem[] = [
    { name: 'A' },
    { name: 'B', disabled: true },
    { name: 'C' }
];
</script>

<style scoped>
.gap {
    height: 10px;
}
</style>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom root element styleUTSJSONObject--
customClassCustom root element style classstring''-
listOption list; each item has a name text and an optional disabledSubsectionListItem[]--
currentIndex of the selected option (0-based)number | string0-
activeColorColor of the selected option; defaults to $u.color.mainColorstring''-
inactiveColorColor of unselected options; defaults to $u.color.contentColorstring''-
modeDisplay mode: button – sliding button, subsection – segmentedSubsectionMode'button'-
fontSizeOption text size, in pxnumber | string14-
heightComponent height, in pxnumber | string35-
animationWhether to animate the sliding buttonbooleantrue-
boldWhether the selected option's text is boldbooleantrue-
bgColorOuter background color in button mode; defaults to $u.color.dividerColorstring''-
buttonColorSliding button color in button mode; defaults to $u.color.bgWhitestring''-
vibrateShortWhether to trigger a light vibration on switch (skipped on the first switch)booleanfalse-
disabledWhether to disable the whole componentbooleanfalse-

Events ​

EventDescriptionParamsVersion
changeFires when the selected option changes; the callback is the selected indexindex: number-

Slots ​

ux-subsection has no slots.

Notes ​

  1. current is controlled: update it from @change. A click first compares against the internal index, and returns early when the target is already selected, so change is not emitted again.
  2. The slider width is measured from the first option (getBoundingClientRectAsync). H5 re-measures on window resize, while App / WeChat Mini Program only re-measure on mount and when list or mode changes; if the container width changes at runtime (e.g. orientation change), the slider may be misaligned.
  3. bgColor / buttonColor apply to button mode only. In subsection mode the selected text is always white ($u.color.whiteColor), so a very light active-color makes it hard to read.
  4. A disabled item, or a component with disabled, ignores clicks and emits no change. A disabled item's text drops to 0.4 opacity; the whole component drops to 0.6 when disabled.
  5. With vibrateShort, the first switch does not vibrate (an internal first-touch guard); later switches do.