Disclaimer
!important: In most cases, you should not use Input component in your application. Input component is a base for other inputs and was not designed to be used directly.
Usage
Input component is used as base for some other inputs (Select, TextInput, Textarea, etc.).
The purpose of Input is to provide shared styles and features to other inputs:
Icon and right section
Custom component
Input is a polymorphic component, you can change the root element with component prop:
You can use Input and Input.Wrapper components to build custom inputs with third-party
libraries, example with react-input-mask:
Input.Wrapper component
Input.Wrapper component is used in all other inputs (TextInput, Autocomplete, MultiSelect, etc.)
under the hood, you do not need to wrap your inputs with it, as it is already included in all of them.
Use Input.Wrapper only when you want to create custom inputs.
inputContainer
With inputContainer prop you can enhance inputs that use Input.Wrapper under the hood,
for example, you can add Tooltip to TextInput when
the input is focused:
inputWrapperOrder
inputWrapperOrder prop allows to define the order of Input.Wrapper parts:
required and withAsterisk props
All components that are based on Input.Wrapper support required and withAsterisk props.
When set to true, both of these props will add red asterisk to the end of the label.
The only difference is whether input element will have required attribute, example with
TextInput component:
Input.Label, Input.Error and Input.Description
Input.Label, Input.Error and Input.Description components can be used to create custom
form layouts if default Input.Wrapper layout does not fit your requirements.
InputBase component
InputBase component combines Input and Input.Wrapper components and supports component prop:
Input.Placeholder
Input.Placeholder component can be used to add placeholder to Input and InputBase components that are based on button element
or do not support placeholder property natively:
Default props on MantineProvider
You can add default props on MantineProvider
to Input and Input.Wrapper components. These default props will be inherited by all inputs
that use Input and Input.Wrapper under the hood (TextInput, Autocomplete, MultiSelect, etc.):
Styles on MantineProvider
Same as with default props you can use Input and Input.Wrapper Styles API
on MantineProvider to add styles to all Inputs:
Customize focus styles
Input component is used as a base for other inputs (PasswordInput, Select, MultiSelect, etc.).
To customize focus styles of any inputs that are built on top of the Input component, use &:focus-within selector instead of &:focus:
Get input ref
Input component props
| Name | Type | Description |
|---|---|---|
| disabled | boolean | Disabled input state |
| icon | ReactNode | Adds icon on the left side of input |
| iconWidth | Width<string | number> | Width of icon section in px |
| invalid | boolean | Sets border color to red and aria-invalid=true on input element |
| multiline | boolean | Will input have multiple lines? |
| pointer | boolean | Determines whether cursor on input should be pointer |
| radius | number | "xs" | "sm" | "md" | "lg" | "xl" | Input border-radius from theme or number to set border-radius in px |
| required | boolean | Sets required on input element |
| rightSection | ReactNode | Right section of input, similar to icon but on the right |
| rightSectionProps | Record<string, any> | Props spread to rightSection div element |
| rightSectionWidth | Width<string | number> | Width of right section, is used to calculate input padding-right |
| size | "xs" | "sm" | "md" | "lg" | "xl" | Input size |
| variant | "unstyled" | "default" | "filled" | Defines input appearance, defaults to default in light color scheme and filled in dark |
| wrapperProps | Record<string, any> | Properties spread to root element |
Input.Wrapper component props
| Name | Type | Description |
|---|---|---|
| children * | ReactNode | Input that should be wrapped |
| description | ReactNode | Input description, displayed after label |
| descriptionProps | Record<string, any> | Props spread to description element |
| error | ReactNode | Displays error message after input |
| errorProps | Record<string, any> | Props spread to error element |
| id | string | htmlFor label prop |
| inputContainer | (children: ReactNode) => ReactNode | Input container component, defaults to React.Fragment |
| inputWrapperOrder | ("input" | "label" | "error" | "description")[] | Controls order of the Input.Wrapper elements |
| label | ReactNode | Input label, displayed before input |
| labelElement | "div" | "label" | Render label as label with htmlFor or as div |
| labelProps | Record<string, any> | Props spread to label element |
| required | boolean | Adds required attribute to the input and red asterisk on the right side of label |
| size | "xs" | "sm" | "md" | "lg" | "xl" | Controls all elements font-size |
| withAsterisk | boolean | Determines whether required asterisk should be rendered, overrides required prop, does not add required attribute to the input |
Input.Label component props
| Name | Type | Description |
|---|---|---|
| children | ReactNode | Label content |
| labelElement | "div" | "label" | Label root element |
| required | boolean | Determines whether required asterisk should be displayed |
| size | "xs" | "sm" | "md" | "lg" | "xl" | Predefined label size |
Input.Description component props
| Name | Type | Description |
|---|---|---|
| children | ReactNode | Description content |
| size | "xs" | "sm" | "md" | "lg" | "xl" | Predefined size |
Input.Error component props
| Name | Type | Description |
|---|---|---|
| children | ReactNode | Error content |
| size | "xs" | "sm" | "md" | "lg" | "xl" | Predefined size |
Input component Styles API
| Name | Static selector | Description |
|---|---|---|
| wrapper | .mantine-Input-wrapper | Root Input element |
| invalid | .mantine-Input-invalid | Invalid input modifier |
| disabled | .mantine-Input-disabled | Invalid disabled modifier |
| icon | .mantine-Input-icon | Input icon wrapper on the left side of the input, controlled by icon prop |
| withIcon | .mantine-Input-withIcon | Input element styles when used with icon, controlled by icon prop |
| input | .mantine-Input-input | Main input element |
| rightSection | .mantine-Input-rightSection | Input right section, controlled by rightSection prop |
Input.Wrapper component Styles API
| Name | Static selector | Description |
|---|---|---|
| root | .mantine-Input.Wrapper-root | Root element |
| label | .mantine-Input.Wrapper-label | Label element styles, defined by label prop |
| error | .mantine-Input.Wrapper-error | Error element styles, defined by error prop |
| description | .mantine-Input.Wrapper-description | Description element styles, defined by description prop |
| required | .mantine-Input.Wrapper-required | Required asterisk element styles, defined by required prop |