Skip to content

Picker ​

Bottom-sheet single-column wheel picker. Options are an array of strings, and the selected value is an index.

Spec source: lh-ui-core/specs/picker.json · Golden cases: lh-ui-core/cases/picker.json (13 cases, translated into hypium tests)

Declarative visibility

When visible is false, nothing is rendered; after confirm / cancel, onClose fires and the host sets it back to false. The component must be mounted as the last child of the page's Stack. value is the index of the selected option (0-based); when out of range it is clamped into the options range (golden cases clamp-*).

Basic usage ​

9:41Picker basics
Please select
Option one
Option two
Option three

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
LhPicker({
  visible: this.pickerVisible,
  options: ['Option one', 'Option two', 'Option three'],
  value: this.pickedIndex,
  title: 'Please select',
  onValueChange: (value: number) => { this.pickedIndex = value },
  onConfirm: (value: number) => { this.pickedIndex = value },
  onCancel: () => {},
  onClose: () => { this.pickerVisible = false },
})

The wheel's selected item updates live while dragging (onValueChange); confirming fires onConfirm with the current index.

API ​

Props ​

PropDescriptionTypeDefault
visibleWhether to show; nothing is rendered when falsebooleanfalse
optionsArray of option texts (single column)string[][]
valueSelected option index (0-based); clamped into the options range when out of rangenumber0
titleTitle in the middle of the toolbarstringLanguage pack (@lh-i18n)
confirmTextConfirm button labelstringLanguage pack (@lh-i18n)
cancelTextCancel button labelstringLanguage pack (@lh-i18n)
onValueChangeFired when the wheel stops and the selection changes(value: number) => voidEmpty function
onConfirmFired on confirm with the currently selected index (onClose follows)(value: number) => voidEmpty function
onCancelFired on cancel (onClose follows)() => voidEmpty function
onCloseFired after confirm / cancel() => voidEmpty function

Token reference ​

TokenPurpose
picker.heightPanel height (260vp)
picker.toolbarHeightTop toolbar height (44vp)
picker.itemHeightOption height (the wheel's single-page height, 40vp)
picker.itemFontSizeOption font size (14)
picker.borderRadiusPanel top corner radius
color.background.default / color.background.overlayPanel background / scrim color
color.text.primary / color.text.secondarySelected / adjacent item text color
color.primary.defaultConfirm button and selected-item highlight color
color.border.lighterDividers between the toolbar and the wheel's selected band
shadow.basePanel shadow
zIndex.modalBackdrop / zIndex.modalScrim / sheet elevation
typography.fontSize.medium / fontSize.baseTitle / button font size

Golden case reference ​

How the 13 assertions in cases/picker.json map onto hypium tests (entry/src/test/Picker.test.ets):

case idAssertionLocal test
confirm-emits-onconfirm-with-valueConfirm fires onConfirm with the current valueresolve_clamps_selected_index
confirm-also-emits-oncloseConfirm also fires onClosetoolbar_colors_use_tokens
cancel-emits-oncancelCancel fires onCanceltoolbar_colors_use_tokens
scroll-emits-onvaluechangeA wheel change fires onValueChangewheel_height_minus_toolbar
clamp-negative-value-to-zeroA negative index is clamped to 0clamp_negative_value_to_zero
clamp-overflow-value-to-lastAn overflowing index is clamped to the last itemclamp_overflow_value_to_last
title-renders-textThe title renders texttoolbar_colors_use_tokens
hidden-not-renderedNothing is rendered while hiddenoverlay_and_zindex_use_tokens (visible gate)
confirm-text-fallback-locale确认 label falls back to language pack when unsetpicker_texts_fall_back_to_pack(Locale.test.ets)
cancel-text-fallback-locale取消 label falls back to language pack when unsetpicker_texts_fall_back_to_pack(Locale.test.ets)
confirm-text-explicit-winsExplicit 确认 text wins over the packpicker_texts_fall_back_to_pack(Locale.test.ets)
title-fallback-localeTitle falls back to language pack when unsetpicker_texts_fall_back_to_pack(Locale.test.ets)
title-empty-hides-nodeEmpty string hides the title nodepicker_title_empty_stays_empty(Locale.test.ets)

Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)