Select
nativeui/selectFreeComponent
A select component for React Native applications.
Live preview
live · rendered by the registry
Rendered by nativeui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nativeui.ribbi.ch/r/select.jsonSource
1import * as React from "react";2import { View, Text, Pressable, ScrollView, Platform } from "react-native";3import { Ionicons } from "@expo/vector-icons";4import { cn } from "@/lib/utils";5import { Drawer, useDrawer } from "@/components/ui/drawer";67interface SelectProps {8 value?: string;9 onValueChange?: (value: string) => void;10 placeholder?: string;11 disabled?: boolean;12 className?: string;13 triggerClassName?: string;14 contentClassName?: string;15 size?: "small" | "medium" | "large" | "full" | number[];16 initialSnapIndex?: number;17 avoidKeyboard?: boolean;18 children: React.ReactNode;19}2021interface SelectItemProps {22 value: string;23 children: React.ReactNode;24 disabled?: boolean;25 className?: string;26 selectedValue?: string;27}2829interface SelectLabelProps {30 children: React.ReactNode;31 className?: string;32}3334interface SelectGroupProps {35 children: React.ReactNode;36 className?: string;37}3839interface SelectSeparatorProps {40 className?: string;41}4243interface SelectContextValue {44 selectedValue?: string;45 onSelect: (value: string, label: React.ReactNode) => void;46}4748const SelectContext = React.createContext<SelectContextValue>({49 selectedValue: undefined,50 onSelect: () => { },51});5253const Select = React.forwardRef<View, SelectProps>(54 (55 {56 value,57 onValueChange,58 placeholder,59 disabled = false,60 className,61 triggerClassName,62 contentClassName,63 size = "medium",64 initialSnapIndex = 0,65 avoidKeyboard = true,66 children,67 },68 ref69 ) => {70 const [open, setOpen] = React.useState(false);71 const [selectedValue, setSelectedValue] = React.useState(value);72 const [selectedLabel, setSelectedLabel] =73 React.useState<React.ReactNode>("");7475 React.useEffect(() => {76 if (value !== selectedValue) {77 setSelectedValue(value);78 }79 }, [value, selectedValue]);80 React.useEffect(() => {81 if (selectedValue === undefined) return;8283 let found = false;8485 const findLabel = (child: React.ReactNode) => {86 if (!React.isValidElement(child)) return;8788 const childElement = child as React.ReactElement<any>;8990 if (91 childElement.type === SelectItem &&92 childElement.props.value === selectedValue93 ) {94 setSelectedLabel(childElement.props.children);95 found = true;96 return;97 }9899 if (childElement.type === SelectGroup) {100// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from nativeui
All 29 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | nativeui | Components | Free | 2 deps | |
| Alertalert | nativeui | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | nativeui | Components | Free | 1 dep | |
| Avataravatar | nativeui | Components | Free | 1 dep | |
| Badgebadge | nativeui | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | nativeui | Components | Free | 2 deps | |
| Buttonbutton | nativeui | Components | Free | 2 deps | |
| Calendarcalendar | nativeui | Components | Free | 4 deps |
