Skip to content
NativeScript Unified

Components

Picker

hlm-picker is a form field styled like the select trigger. It opens a list with a search field, so it suits long lists that a select or a dropdown would make the user scroll through. Give it a title, which heads the list, and options, each a value and a label.

Value: none

One choice closes the list. The list moves the selected options to the top when it opens. Set preserveOrder to keep the order you gave.

Several values

With multiple, choosing an option toggles it. On the web each toggle applies at once, as in a select; in the native app, Done saves the choice. The value is an array, and the field lists the labels.

Value: cheese

Add an option

With allowAdd, the list ends in an "Add new" button. It asks for a name, starting from the search text, and emits it as added. The picker does not add the option itself. Its owner creates it and adds it to options.

Added: nothing yet

Forms

hlm-picker implements Angular's ControlValueAccessor, so it works with ngModel and reactive forms. A single picker's value is a string, or null when nothing is chosen. A multiple picker's value is an array of strings. disabled and a form control's disabled state both turn the field off.

InputTypeDefault
titlestringRequired
options{ value: string; label: string }[][]
valuestring | string[] | nullnull
placeholderstring'Select'
multiplebooleanfalse
allowAddbooleanfalse
preserveOrderbooleanfalse
disabledbooleanfalse

valueChange emits the new value, and added emits the name typed into the "Add new" form.

On the web, the list drops down from the field like a select. Focus moves to the search line, the arrow keys move the highlight, Enter chooses, and Escape or a click outside closes the list. ArrowDown on the field opens it. In the native app, the list opens full screen with ModalDialogService, with a title row and Cancel, and the Android back button cancels it.

HlmPickerHost decides how the list opens. Its web default, HlmPickerDropdownHost, anchors the list to the field with BrnOverlayService. provideSpartanNativeScript() replaces it with NativeScriptPickerHost (packages/ui/native/ui/picker-host.ts). To open the list another way, provide your own HlmPickerHost at the root.