The Input component is a component that is used to get user input in a text field.
const Example = () => {
return <Input mx="3" placeholder="Input" w={{
base: "75%",
md: "25%"
}} />;
};
const Example = () => {
return <Stack mt={3} space={4} w={{
base: "75%",
md: "25%"
}}>
<Center>
<Heading textAlign="center" mb="10">
Input sizes
</Heading>
</Center>
<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={{
base: "75%",
md: "25%"
}}>
<Center>
<Heading textAlign="center" mb="10">
Input Variants
</Heading>
</Center>
<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 alignItems="center">
<InputGroup w={{
base: "70%",
md: "285"
}}>
<InputLeftAddon children={"https://"} />
<Input w={{
base: "70%",
md: "100%"
}} placeholder="nativebase" />
<InputRightAddon children={".io"} />
</InputGroup>
</Stack>;
};
const Example = () => {
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%"
}} InputRightElement={<Icon as={<MaterialIcons name="visibility-off" />} size={5} mr="2" color="muted.400" />} placeholder="Password" />
</Stack>;
};
const Example = () => {
const [show, setShow] = React.useState(false);
const handleClick = () => setShow(!show);
return <Input type={show ? "text" : "password"} w={{
base: "75%",
md: "25%"
}} InputRightElement={<Button size="xs" rounded="none" w="1/6" h="full" onPress={handleClick}>
{show ? "Hide" : "Show"}
</Button>} placeholder="Password" />;
};
const Example = () => {
const [value, setValue] = React.useState("");
const handleChange = event => setValue(event.target.value);
return <Input value={value} w={{
base: "75%",
md: "25%"
}} onChange={handleChange} placeholder="Value Controlled Input" />;
};
const Example = () => {
return <FormControl isInvalid w={{
base: "75%",
md: "25%"
}}>
<FormControl.Label>Password</FormControl.Label>
<Input placeholder="Enter password" />
<FormControl.ErrorMessage leftIcon={<WarningOutlineIcon size="xs" />}>
Try different from previous passwords.
</FormControl.ErrorMessage>
</FormControl>;
};
Input implements
,
,
,
,
,
,
,
,
,
If true, the input will indicate an error.
The variant of the input style to use.
Type: ResponsiveValue<"outline" | "rounded" | (string & {}) | "unstyled" | "underlined" | "filled">
If true, the input will be disabled.
The size of the input.
Type: ResponsiveValue<number | "px" | "0" | (string & {}) | "full" | "sm" | "6" | "2xs" | "8" | "xs" | "12" | "md" | "16" | "xl" | "24" | "32" | "2" | "0.5" | "4" | "3" | "lg" | "1" | "2xl" | "container" | ... 30 more ... | "5/6">
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
If given, adds the provided element to the left 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 given, adds the provided element to the right of the input.
Type: Element | Element[]
Using the type password, user can mask the input.
Ref to be passed to Icon's wrapper Box
Passed props will be applied on hovered state.
Type: Omit<IInputProps, "_hover">
Passed props will be applied on focused state.
Type: Omit<IInputProps, "_focus">
Passed props will be applied on disabled state.
Type: Omit<IInputProps, "_disabled">
Passed props will be applied on readOnly state.
Type: Omit<IInputProps, "_readOnly">
Passed props will be applied on invalid state.
Type: Omit<IInputProps, "_hover">
InputGroup implements
,
,
,
,
,
,
,
,
,
,
The variant of the input style to use.
The size of the input.
Type: ResponsiveValue<number | "px" | "full" | "sm" | "6" | "2xs" | "8" | "xs" | "12" | "md" | "16" | "xl" | "24" | "32" | "2" | "0.5" | "4" | "3" | "lg" | "1" | "2xl" | "0" | "container" | "3xs" | "1.5" | ... 29 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 .