Input
Render a user interface element that resembles or functions as an input field, allowing the user to provide text or other data.
Installation
Input core subcomonents and usage
Input.Group
The Input.Group component serves as a container that groups related Input elements and any associated icons, labels, or buttons. It provides a structural wrapper, typically used when the input has additional elements like labels or icons.
Input.Label
The Input.Label component displays a label for the input field. It dynamically adjusts based on the focus state of the input and the presence of a value. Input.Label is placed as a child within Input.Group.
Input.LeftIcon
The Input.LeftIcon component renders an icon to the left of the input field. This is typically used for visual cues, such as a user icon for a username input. It is placed as a child within Input.Group
Input.LeftIcon
The Input.RightIcon component displays an icon to the right of the input field. This can be useful for showing status icons or action icons. It is placed as a child within Input.Group```tsx
Input.PasswordToggle
The Input.PasswordToggle component is a button that toggles the visibility of the input's password text, changing the input type between password and text. This should be used alongside an Input with type="password
Input.ClearButton
The Input.ClearButton component displays a button to the right of the input that clears the input's value when clicked. This is helpful for input fields that may require quick clearing.
Complete Example with Multiple Elements
Below is a more comprehensive example that combines multiple sub-components.
Input component props
Name | Type | Description |
---|---|---|
variant | default | filled | flushed | flushedfilled | dashed | Defines the visual style of the input field. |
type | string | Specifies the input type, such as "text", "password", etc. |
error | boolean | If true, applies error styling to the input field. |
textError | string | Error message displayed when error is true. |
maxLength | number | Maximum number of characters allowed in the input field. |
value | string | number | Controlled value for the input field. |
required | boolean | If true, marks the input field as required. |
disabled | boolean | If true, disables the input field. |
children | React.ReactNode | Content nested within the input, such as icons or labels. |
ref | React.Ref<HTMLInputElement> | Ref to the input element for direct DOM manipulation. |
onFocus | (e: React.FocusEvent<HTMLInputElement>) => void | Event handler called when the input is focused. |
onBlur | (e: React.FocusEvent<HTMLInputElement>) => void | Event handler called when the input loses focus. |
className | string | Additional CSS classes to style the input component. |
...props | React.InputHTMLAttributes | Additional props like onChange, placeholder, etc. |