The Input component allows a user to provide input in a text field.
const Example = () => {
return <Input shadow={2} _light={{
bg: "coolGray.100",
_hover: {
bg: "coolGray.200"
},
_focus: {
bg: "coolGray.200:alpha.70"
}
}} _dark={{
bg: "coolGray.800",
_hover: {
bg: "coolGray.900"
},
_focus: {
bg: "coolGray.900:alpha.70"
}
}} placeholder="Enter your name" />;
};
const Example = () => {
return <Box alignItems="center">
<Input mx="3" placeholder="Input" w="100%" />
</Box>;
};
const Example = () => {
return <Stack space={4} w="75%" maxW="300px" mx="auto">
<Input size="xs" placeholder="xs Input" />
<Input size="sm" placeholder="sm Input" />
<Input size="md" placeholder="md Input" />
<Input size="lg" placeholder="lg Input" />
<Input size="xl" placeholder="xl Input" />
<Input size="2xl" placeholder="2xl Input" />
</Stack>;
};
const Example = () => {
return <Stack space={4} w="75%" maxW="300px" mx="auto">
<Input variant="outline" placeholder="Outline" />
<Input variant="filled" placeholder="Filled" />
<Input variant="underlined" placeholder="Underlined" />
<Input variant="unstyled" placeholder="Unstyled" />
<Input variant="rounded" placeholder="Round" />
</Stack>;
};
const Example = () => {
return <Stack>
<InputGroup w={{
base: "70%",
md: "285"
}} justifyContent="center">
<InputLeftAddon children={"https://"} />
<Input w={{
base: "70%",
md: "100%"
}} placeholder="nativebase" />
<InputRightAddon children={".io"} />
</InputGroup>
</Stack>;
};
const Example = () => {
const [show, setShow] = React.useState(false);
return <Stack space={4} w="100%" alignItems="center">
<Input w={{
base: "75%",
md: "25%"
}} InputLeftElement={<Icon as={<MaterialIcons name="person" />} size={5} ml="2" color="muted.400" />} placeholder="Name" />
<Input w={{
base: "75%",
md: "25%"
}} type={show ? "text" : "password"} InputRightElement={<Pressable onPress={() => setShow(!show)}>
<Icon as={<MaterialIcons name={show ? "visibility" : "visibility-off"} />} size={5} mr="2" color="muted.400" />
</Pressable>} placeholder="Password" />
</Stack>;
};
const Example = () => {
const [show, setShow] = React.useState(false);
const handleClick = () => setShow(!show);
return <Box alignItems="center">
<Input type={show ? "text" : "password"} w="100%" py="0" InputRightElement={<Button size="xs" rounded="none" w="1/6" h="full" onPress={handleClick}>
{show ? "Hide" : "Show"}
</Button>} placeholder="Password" />
</Box>;
};
const Example = () => {
const [value, setValue] = React.useState("");
const handleChange = text => setValue(text);
return <Box alignItems="center">
<Input value={value} w="100%" onChangeText={handleChange} placeholder="Value Controlled Input" />
</Box>;
};
const Example = () => {
return <Box alignItems="center">
<FormControl isInvalid w="75%" maxW="300px">
<FormControl.Label>Password</FormControl.Label>
<Input placeholder="Enter password" />
<FormControl.ErrorMessage leftIcon={<WarningOutlineIcon size="xs" />}>
Try different from previous passwords.
</FormControl.ErrorMessage>
</FormControl>
</Box>;
};
Input implements
,
,
,
,
,
,
,
,
,
The size of the input.
Type: ThemeComponentSizeType<"Input">
The variant of the input style to use.
Type: ResponsiveValue<"outline" | "underlined" | "rounded" | "filled" | "unstyled" | (string & {})>
If true, the input will be hovered.
If true, the input will be focused.
If given, adds the provided element to the left of the input.
Type: Element | Element[]
If given, adds the provided element to the right of the input.
Type: Element | Element[]
If given, adds the provided element to the left of the input.
Type: Element | Element[]
If given, adds the provided element to the right of the input.
Type: Element | Element[]
If true, the input will indicate an error.
If true, the input will be disabled.
This will set aria-required="true" on web when passed in formcontrol.
If true, prevents the value of the input from being edited.
If true, the input element will span the full width of its parent
Using the type password, user can mask the input.
Type: "text" | "password"
Ref to be passed to Icon's wrapper Box
Passed props will be applied on hovered state.
Type: Partial<IInputProps>
Passed props will be applied on focused state.
Type: Partial<IInputProps>
Passed props will be applied on disabled state.
Type: Partial<IInputProps>
Passed props will be applied on readOnly state.
Type: Partial<IInputProps>
Passed props will be applied on invalid state.
Type: Partial<IInputProps>
props are passed to InputBase component
Type: Partial<IInputProps>
Props to be passed to the Stack used inside.
Type: Partial<IStackProps>
This prop allows you to change outlineColor when input is in the focused state
This prop allows you to change outlineColor when input is in invalid state
InputGroup implements
,
,
,
,
,
,
,
,
,
The variant of the input style to use.
The size of the input.
Type: ResponsiveValue<number | "px" | "full" | "sm" | "6" | "2xs" | "2" | "8" | "xs" | "3" | "12" | "md" | "4" | "16" | "xl" | "5" | "24" | "32" | "7" | "0.5" | "2.5" | "lg" | "1" | "2xl" | "1.5" | "10" | "20" | ... 27 more ... | (string & {})>
NativeBase ships with a default theme for each component. Check out the default theme of the input
.
Info:
We can easily extend the input component theme using extendTheme function as described in the documentation .