Skip to Content

Built by moveinready.casa  and the community

Shadcn Docs

Input

Displays a form input field or a component that looks like an input field.

Usage

import {Input} from "@/components/ui/input"; <Input placeholder="Email" />;

Props

Input

PropTypeDefaultDescription
variant"shadcn" | "outlined" | "ghost""shadcn"Visual variant of the input.
size"sm" | "md" | "lg" | "xl""md"Size of the input (controls height and some spacing).
borderRadius"none" | "sm" | "md" | "lg" | "xl""md"Corner radius of the input.
color"primary" | "secondary" | "success" | "warning" | "destructive""primary"Color family primarily applied to borders.
disabledbooleanfalseWhether the input is disabled (non-editable and marked disabled for accessibility).
readOnlybooleanfalseWhether the input is read-only (non-editable but not marked disabled for accessibility).
requiredbooleanfalseWhether the input is required (adds visual affordance and accessibility hint text).
clearablebooleanfalseShows a clear button when the field has a value.
startContentReact.ReactNode-Optional leading adornment.
endContentReact.ReactNode-Optional trailing adornment.
baseClassNamestring-Tailwind classes applied to the wrapper slot (takes priority over className).
inputClassNamestring-Tailwind classes applied to the inner TextInput slot.
clearButtonClassNamestring-Tailwind classes applied to the clear button slot.
testIDstring-Test identifier applied to the wrapper.

Also extends all React Native TextInput props.

Hooks

useInput

The backbone hook for the input component that manages controlled/uncontrolled value, clear button visibility, and accessibility props.

Parameters:

ParameterTypeDefaultDescription
onChangeText(text: string) => void-Callback invoked when the text changes.
disabledbooleanfalseWhether the input is disabled.
readOnlybooleanfalseWhether the input is read-only.
requiredbooleanfalseWhether the input is required; augments accessibility hint.
clearablebooleanfalseWhether to render a clear button when value is non-empty.
valuestring-Controlled value of the input.
defaultValuestring-Uncontrolled initial value of the input.
accessibilityHintstring-Additional accessibility hint text.

Returns:

{ state: { isFocused: boolean; setIsFocused: (isFocused: boolean) => void; showClear: boolean; }; componentProps: ComponentProps<typeof View> | HTMLDivElement; inputProps: ComponentProps<typeof TextInput> | HTMLInputElement; clearButtonProps: ComponentProps<typeof Pressable> | HTMLButtonElement; }
PropertyTypeDescription
state.isFocusedbooleanWhether the input currently has focus.
state.setIsFocused(isFocused: boolean) => voidSetter to update focus state.
state.showClearbooleanWhether the clear button should be visible.
componentPropsComponentProps<typeof View> | HTMLDivElementAccessibility props for the wrapper element.
inputPropsComponentProps<typeof TextInput> | HTMLInputElementProps to apply to the TextInput element.
clearButtonPropsComponentProps<typeof Pressable> | HTMLButtonElementProps to apply to the clear button element.

Accessibility

  • Wrapper uses accessibilityRole="text" and sets accessibilityState={{disabled}} when disabled.
  • required adds hint text and a visual indicator.
  • Clear button is exposed as accessibilityRole="button".

Styling

Input Classes

Slots:

  • base - For the wrapper View in the input component
  • input - For the inner TextInput element
  • clearButton - For the clear Pressable element

Variants:

  • variant:
    • shadcn - Background + input border + light shadow
    • outlined - Transparent background with input border
    • ghost - Transparent background with no border shadow
  • size:
    • sm - h-8
    • md - h-9
    • lg - h-10
    • xl - h-12
  • borderRadius:
    • none - rounded-none
    • sm - rounded-sm
    • md - rounded-md
    • lg - rounded-lg
    • xl - rounded-xl
  • color:
    • primary, secondary, success, warning, destructive - border color

shadcn-native

Built by moveinready.casa and the community