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
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
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
| Prop | Description | Type | Default |
|---|---|---|---|
visible | Whether to show; nothing is rendered when false | boolean | false |
options | Array of option texts (single column) | string[] | [] |
value | Selected option index (0-based); clamped into the options range when out of range | number | 0 |
title | Title in the middle of the toolbar | string | Language pack (@lh-i18n) |
confirmText | Confirm button label | string | Language pack (@lh-i18n) |
cancelText | Cancel button label | string | Language pack (@lh-i18n) |
onValueChange | Fired when the wheel stops and the selection changes | (value: number) => void | Empty function |
onConfirm | Fired on confirm with the currently selected index (onClose follows) | (value: number) => void | Empty function |
onCancel | Fired on cancel (onClose follows) | () => void | Empty function |
onClose | Fired after confirm / cancel | () => void | Empty function |
Token reference
| Token | Purpose |
|---|---|
picker.height | Panel height (260vp) |
picker.toolbarHeight | Top toolbar height (44vp) |
picker.itemHeight | Option height (the wheel's single-page height, 40vp) |
picker.itemFontSize | Option font size (14) |
picker.borderRadius | Panel top corner radius |
color.background.default / color.background.overlay | Panel background / scrim color |
color.text.primary / color.text.secondary | Selected / adjacent item text color |
color.primary.default | Confirm button and selected-item highlight color |
color.border.lighter | Dividers between the toolbar and the wheel's selected band |
shadow.base | Panel shadow |
zIndex.modalBackdrop / zIndex.modal | Scrim / sheet elevation |
typography.fontSize.medium / fontSize.base | Title / 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 id | Assertion | Local test |
|---|---|---|
confirm-emits-onconfirm-with-value | Confirm fires onConfirm with the current value | resolve_clamps_selected_index |
confirm-also-emits-onclose | Confirm also fires onClose | toolbar_colors_use_tokens |
cancel-emits-oncancel | Cancel fires onCancel | toolbar_colors_use_tokens |
scroll-emits-onvaluechange | A wheel change fires onValueChange | wheel_height_minus_toolbar |
clamp-negative-value-to-zero | A negative index is clamped to 0 | clamp_negative_value_to_zero |
clamp-overflow-value-to-last | An overflowing index is clamped to the last item | clamp_overflow_value_to_last |
title-renders-text | The title renders text | toolbar_colors_use_tokens |
hidden-not-rendered | Nothing is rendered while hidden | overlay_and_zindex_use_tokens (visible gate) |
confirm-text-fallback-locale | 确认 label falls back to language pack when unset | picker_texts_fall_back_to_pack(Locale.test.ets) |
cancel-text-fallback-locale | 取消 label falls back to language pack when unset | picker_texts_fall_back_to_pack(Locale.test.ets) |
confirm-text-explicit-wins | Explicit 确认 text wins over the pack | picker_texts_fall_back_to_pack(Locale.test.ets) |
title-fallback-locale | Title falls back to language pack when unset | picker_texts_fall_back_to_pack(Locale.test.ets) |
title-empty-hides-node | Empty string hides the title node | picker_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.

