Components/Picker

Picker

A wheel picker that selects one value per column.

VerifiedSince 0.3.4

Usage

v-model:visible controls the popup, popup="false" renders inline, and itemHeight / visibleItemCount size the rows.

Loading demo...

Best Practices

  • Keep modelValue a complete array ordered like columns; sparse arrays are normalized, but explicit values keep form state auditable.
  • Give each column a key when columns reorder or render conditionally, so Vue doesn't reuse an old column for different data.
  • Use stable primitive option values and put display text in label.
  • Use inline mode (popup=false) for always-visible settings, and the popup for mobile or short tasks.
  • Don't submit disabled values: the component skips disabled options only when it normalizes or recovers a scroll.

API Reference

Props

PropTypeDefaultDescription
modelValuePickerValue[]One value per column; missing or invalid values fall back to the first enabled option.
columnsPickerColumn[][]Column definitions, left to right.
visiblebooleanfalsePopup visibility, bound with v-model:visible.
popupbooleantruetrue teleports a bottom popup; false renders inline.
titlestring''Toolbar title.
showToolbarbooleantrueShows the cancel, title, and confirm toolbar.
confirmTextstring'Confirm'Confirm button text.
cancelTextstring'Cancel'Cancel button text.
disabledbooleanfalseDisables the toolbar, the options, and dragging.
itemHeightnumber36Row height in px; at least 24.
visibleItemCountnumber5Visible rows; even counts round up to odd, at least 3.
closeOnClickMaskbooleantrueCloses the popup when the mask is clicked.
lazyMountbooleantrueMounts the popup body on first open.

Events

EventParamsDescription
update:modelValue(value: PickerValue)Fires when turning a column changes its value.
change(value: PickerValue)Fires together with update:modelValue.
update:visible(visible: boolean)Fires on open and close.
confirm(value: PickerValue)Fires with the current value on confirm, then closes.
cancel-Fires on cancel, then closes.
open-Fires on open.
close-Fires on close.

Exposed Methods

NameTypeDescription
open() => voidOpens the popup by writing visible=true.
close() => voidCloses the popup.
toggle() => voidToggles the popup.

Types

type PickerValue = Array<string | number>

PickerColumn, one entry of columns:

FieldTypeDescription
keystringOptional stable key.
optionsPickerOption[]The column's options.

PickerOption, one entry of options:

FieldTypeDescription
valuestring | numberPrimitive value emitted for the column.
labelstringVisible text.
disabledbooleanPrevents selection; skipped by the normalization fallback.

Overview

  • Each column is a drum the component turns itself, not a native scroller; it handles the pointer, the wheel, clicks, and the keyboard.
  • A drag tracks the pointer, then coasts on its release velocity and settles on the nearest enabled row with a cubic ease-out; the wheel settles 120ms after it stops.
  • Under reduced motion a drag still tracks the pointer, but there is no coast and settling doesn't ease.
  • When a controlled parent echoes back the value a column is already turning to, the column finishes its turn instead of being re-placed.
  • Only the rows facing the viewer are drawn (11 at the default size, whatever the column length); each carries aria-setsize and aria-posinset, so screen readers see the full list.

Technologies

  • Rows sit on the drum by rotateX of their distance from the offset (defaults: r = 116px, a 17.6° step, a 348px perspective); rows skip hit testing, and a click resolves to its row by inverting the projection in closed form.
  • Source: packages/tuffex/packages/components/src/picker/.
查看源码
packages/tuffex/packages/components/src/picker/index.ts