Command palette

@yasinsensoy/native

React Native · Components

Select

Select box.

11 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { Label, Select } from "@yasinsensoy/native";

<Label htmlFor="selection">Selection</Label>
<Select id="selection" name="selection"
  items={[
    { group: "Ekip", items: [
      { value: "owner", label: "Sahip", icon: "user", description: "Everything, including invoices" },
      { value: "editor", label: "Editor", icon: "pencil" },
    ] },
    { group: "External", items: [
      { value: "auditor", label: "Auditor", disabled: true, tooltip: "Available on the business plan" },
    ] },
  ]}
  onValueChange={(value) => …} />

Events

  1. Events appear here when you interact with the preview.

SelectField: etiket, zorunlu alan ve form

You can pick more than one.

Import

import { Select } from "@yasinsensoy/native";

Select

component

Select box. On phones a themed panel opens from the bottom (rows tall enough for comfortable thumb taps, closes by pulling down and with the back button); on tablets a list opens below the box. The operating system's picker is not used; it looks the same on iOS and Android.

  • Options can be plain text, { value, label, icon, description, disabled } or { group, items }. Search ignores diacritic differences (including Turkish characters) and highlights the match.
  • Long lists are virtual; items can be a Promise or a function, and loadItems does server-side search and pagination.
  • Multiple selection with multiple.
Select(props: SelectProps): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<Select label="City" placeholder="Choose a city"
  items={["Istanbul", "Ankara", { group: "Aegean", items: ["Izmir", "Mugla"] }]} />
<Select multiple label="Tags" items={tags} value={selected} onValueChange={setSelected} />

SelectItem

interface

An option inside Select (same as web).

NameTypeDescription
valuestringThe value used with value/onValueChange.
label?ReactNodeDisplay text. Defaults to value.
icon?IconPropIcon before the text.
description?ReactNodeSmall description under the text.
disabled?booleanCannot be selected.
keywords?readonly string[]Extra words to match in search (e.g. a plate code).

SelectGroup

interface

Option group with a heading.

NameTypeDescription
groupReactNodeGroup heading.
itemsreadonly (string | SelectItem)[]Options in the group.

An element of the items array: plain text, an option object or a group.

type SelectEntry = string | SelectItem | SelectGroup

SelectPage

interface

One page of the loadItems response.

NameTypeDescription
itemsreadonly SelectEntry[]Items on this page.
hasMore?booleanAre there more pages?

Information passed to loadItems.

NameTypeDescription
querystringSearch text (may be empty).
pagenumberRequested page; the first page is 0.
signalAbortSignalCancels the stale request when the search changes or the list closes.

Source of the options: an array, a Promise or a function called once.

type SelectItemsSource = readonly SelectEntry[] | Promise<readonly SelectEntry[]> | (() => Promise<readonly SelectEntry[]>)

Loader that searches and paginates on the server.

type SelectLoader = (context: SelectLoadContext) => Promise<readonly SelectEntry[] | SelectPage>

Single selection.

Extends: FieldProps

NameTypeDefaultDescription
multiple?falseSingle selection.
value?stringSelected value (controlled); "" is empty.
defaultValue?stringInitial value.
onValueChange?(value: string, item: SelectItem | undefined) => voidWhen the selection changes.
renderValue?(item: SelectItem) => ReactNodeHow the selected item looks in the box.
items?SelectItemsSourceOptions: an array, a Promise or a function called once.
loadItems?SelectLoaderFunction that searches on the server and fetches page by page (search waits 250 ms, the stale request is cancelled).
search?boolean | "auto""auto"Search box: "auto" with more than 20 options.
searchPlaceholder?stringthe {@link UIProvider} `search` textPlaceholder of the search box.
placeholder?ReactNode{@link UIProvider} `select` textText shown when nothing is selected.
emptyMessage?ReactNodeWhen there are no options or the search finds nothing.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseButton that clears the selection.
open?booleanIs the list open, in controlled use?
defaultOpen?booleanfalseInitially open?
onOpenChange?(open: boolean) => voidWhen the list opens or closes.
variant?FieldVariant"outline"Field appearance.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.

Multiple selection.

Extends: FieldProps

NameTypeDefaultDescription
multipletrueMultiple values can be selected; the list does not close on selection.
value?readonly string[]Selected values (controlled).
defaultValue?readonly string[]Initial values.
onValueChange?(value: string[], items: SelectItem[]) => voidWhen the selection changes.
renderValue?(items: SelectItem[]) => ReactNodeHow the selected items look in the box.
items?SelectItemsSourceOptions: an array, a Promise or a function called once.
loadItems?SelectLoaderFunction that searches on the server and fetches page by page (search waits 250 ms, the stale request is cancelled).
search?boolean | "auto""auto"Search box: "auto" with more than 20 options.
searchPlaceholder?stringthe {@link UIProvider} `search` textPlaceholder of the search box.
placeholder?ReactNode{@link UIProvider} `select` textText shown when nothing is selected.
emptyMessage?ReactNodeWhen there are no options or the search finds nothing.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseButton that clears the selection.
open?booleanIs the list open, in controlled use?
defaultOpen?booleanfalseInitially open?
onOpenChange?(open: boolean) => voidWhen the list opens or closes.
variant?FieldVariant"outline"Field appearance.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.

Select props (same names as web).

type SelectProps = SingleSelectProps | MultiSelectProps

Extends: FieldProps

NameTypeDefaultDescription
multiple?false | trueSingle selection.
value?string | readonly string[]Selected value (controlled); "" is empty.
defaultValue?string | readonly string[]Initial value.
onValueChange?(value: string, item: SelectItem | undefined) => void | (value: string[], items: SelectItem[]) => voidWhen the selection changes.
renderValue?(item: SelectItem) => ReactNode | (items: SelectItem[]) => ReactNodeHow the selected item looks in the box.
items?SelectItemsSourceOptions: an array, a Promise or a function called once.
loadItems?SelectLoaderFunction that searches on the server and fetches page by page (search waits 250 ms, the stale request is cancelled).
search?boolean | "auto""auto"Search box: "auto" with more than 20 options.
searchPlaceholder?stringthe {@link UIProvider} `search` textPlaceholder of the search box.
placeholder?ReactNode{@link UIProvider} `select` textText shown when nothing is selected.
emptyMessage?ReactNodeWhen there are no options or the search finds nothing.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseButton that clears the selection.
open?booleanIs the list open, in controlled use?
defaultOpen?booleanfalseInitially open?
onOpenChange?(open: boolean) => voidWhen the list opens or closes.
variant?FieldVariant"outline"Field appearance.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.