Components/SegmentedSlider

SegmentedSlider

A slider for choosing one of a fixed set of discrete steps.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Custom Segments

A value can be a string, and a label any text, emoji included.

Loading demo...

Release Policy

Use TxSegmentedSlider for the risk tier and TxSlider for the traffic ratio.

Loading demo...

Best Practices

  • Use 3–7 stable segments; switch to TxSelect or TxSearchSelect for long or dynamic lists.
  • Keep each segment value primitive and unique.
  • Turn off showLabels only when nearby text already explains each step.
  • Use TxSlider for continuous numbers and TxSegmentedSlider for ordered tiers such as risk, plan, or quality gates.

API Reference

Props

PropTypeDefaultDescription
modelValuenumber | string | null0Selected segment value; null selects the first segment after mount.
segmentsSegmentedSliderSegment[][]Segments, in order along the track.
disabledbooleanfalseBlocks changes by click and keyboard.
showLabelsbooleantrueShows each segment's label, if it has one.
verticalbooleanfalseUses a vertical track that fills bottom-to-top.

Events

EventParamsDescription
update:modelValue(value: number | string)Fires when a segment is chosen by click or keyboard.
change(value: number | string)Fires together with update:modelValue.

Types

EXAMPLE.TS
export interface SegmentedSliderSegment {
  value: number | string // emitted when selected
  label?: string // text beside the stop
}

Overview

  • The track is inset by half an active stop at each end, so the end stops sit wholly inside the box on either axis, and the fill ends at the selected stop's center.
  • The row is a radiogroup and each stop a radio.
  • Tab enters the row once, on the current stop; arrow keys move and stop at both ends, and Home / End jump to them. In the vertical layout, Up moves forward.
  • The focus ring shows only for keyboard use; hover slightly grows an unselected stop. Both stop under reduced motion.

Technologies

  • Source: packages/tuffex/packages/components/src/segmented-slider/.
查看源码
packages/tuffex/packages/components/src/segmented-slider/index.ts