OneScript

Picker

Choose one value from a set of options.

A controlled picker. Each option is a view marked with tag; selection must match exactly one option's tag.

import { Modifier, Picker, Text, useState } from "onescript/views"

function ColorPicker() {
  const [color, setColor] = useState("red")
  return (
    <Picker
      label="Color"
      selection={color}
      onSelectionChange={setColor}
    >
      <Text modifier={Modifier.tag("red")}>Red</Text>
      <Text modifier={Modifier.tag("blue")}>Blue</Text>
    </Picker>
  )
}
PropTypeDescription
selectionstring | numberTag of the selected option.
onSelectionChange(value) => voidRuns with the tag of the option the user chooses.
labelViewChildOptional label.
childrenViewChildOptions. Options can come from arrays, fragments, or components.

Tags must be unique and selection must match one of them; otherwise rendering fails with an error. 1 and "1" are different tags.

Use pickerStyle to switch between menu, segmented, wheel, and other styles. Also accepts Modifiers. It is only available in App and Action view sessions; widgets reject it with an unsupported view type error.

How is this guide?

Last updated on