Input
An Input is a text field users can type into. It supports different text formats and numbers.
Inputs are commonly used to create forms. They can be grouped into sections in a form and are stacked vertically whenever possible. You can also use it as a single input field or search bar.
Inputs come with a descriptive label. In the case of a search function they contain a magnifier icon. Inputs can have a placeholder text to imply expected formatting, e.g. "DD/MM/YYYY".
Example
Usage Rules
Do:
- Use concise labels
- Communicate that an input is optional by including an "optional" info after the label
- Validate input after users have finished interactions with the field and not before
- Indicate in the error text what the problem is and how to fix it
Don’t:
- Use the field without a label
- Use for long texts inputs. If users are expected to type more than one line, use a Textarea instead
- Add examples or complementary information to the label
- Replace the label with an error message. Use the info text instead
Variants
Autocomplete
To offer more flexibility to the users, the autoComplete
property can be used.
Clear Button
To offer functionality to remove the input term an onClear
callback can be added. It displays a clear button and gets called when this button is pressed.
Clear Button testid
You can test the clear button with the testid prop clearTestId
.
Custom Labelled Status Indicating
We can use indicatorCustomLabels
props which needs to match the StatusIndicatorLabelTypes
exported from StatusIndicator
component to show custom lables, when no custom labels are passed, default props are used.
Default value
You can set the initial input content with passing defaultValue
.
Disabled
Info Text
Use an info text to give specific instructions to help users correctly fill in the data. You can also use it to clarify how the data will be used.
When validating data, use the info text to display the error message.
warning
When on firefox, the input and infoText
will take full width by default. If you need the input to have a fixed width and the infoText
to wrap to a second line, please either add css={}
prop, a wrapper element with a fixed width, or a fixed width to the <form>
element.
You can change the position of the info text to be on top of the input.
warning
Please avoid using the Info Text on top of the input when you also need the optional label.
We also support text tags inside the Info Text. Like strong
, b
, i
and a
.
Label
Always include a label to let users know what the input is for.
You can add extra piece of information to the label by including a tooltip.
Prefix
In some cases, we need some prefix to stand out from the actual value. For this, we have the prefix
property which comes before the typing area.
Ref
Access input native element using ref
.
Search
Setting the input type to search
displays a search icon in the input.
Status Indicating
Input field Status Indicator withLabel
, here you can see defautlLabels
for indicatorType
.
progress: 'Saving….'
, positive: 'Saved!'
, negative: 'Disconnected!'
Suffix
In some cases, we need some suffix to stand out from the actual value. For this, we have the suffix
property which comes after the typing area.
Optional field
You can show the field as optional or custom text by using the optionalText
prop as string.
Input field custom styling
Using inputFieldCss
prop you can customise the input field using textTransform options uppercase
, lowercase
or capitalize
.
Props
Name | Type | Default |
---|---|---|
disabled Native HTML attribute: Link |
| — |
type The type of the input |
| "text" |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
label The visual label of the input |
| — |
aria-label Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
aria-labelledby Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
id Native HTML attribute: Link .
Internally, this component uses a random id. We use it to associate an input with a label element.
As the random id might break snapshot tests it can be overridden by setting an explicit id. |
| — |
onFocus Native HTML callback: Link |
| — |
onBlur Native HTML callback: Link |
| — |
onKeyDown Native HTML callback: Link |
| — |
required Native HTML attribute: Link |
| — |
readOnly Native HTML attribute: Link |
| — |
onChange Native HTML callback: Link |
| — |
value The input's value |
| — |
autoFocus Native HTML attribute: Link |
| — |
name Native HTML attribute: Link |
| — |
placeholder Native HTML attribute: Link |
| — |
onClear Adding this callback function will render a button to clear the input field |
| — |
infoText Instructions to help users correctly fill in the data |
| — |
optionalText optionalText value to show the field is optional with custom text |
| — |
autoComplete Native HTML attribute: Link |
| — |
infoTextTop positions the infoText on top of the input |
| — |
defaultValue The input's defaultValue |
| — |
indicatorType The prop for indicatorType which is required to enable the indicator and shows the status based on its given type without label. |
| — |
indicatorCustomLabels The prop for status indicator with custom labels with StatusIndicatorLabelTypes, if not passed uses default props that can be exported from StatusIndicator component. |
| — |
indicatorWithLabel This prop enables the display of a label next the status indicator. If no custom label is passed, it uses the default labels. |
| — |
invalid Visually notify the user that the provided value is invalid |
| — |
min Native HTML attribute: Link |
| — |
max Native HTML attribute: Link |
| — |
step Native HTML attribute: Link |
| — |
minLength Native HTML attribute: Link |
| — |
maxLength Native HTML attribute: Link |
| — |
labelIconTooltip The labelIconTooltip content can either be pure text or any rich content wrapped in a React component
The labelIconTooltip content will be shown when hovering the label icon.
The labelIconTooltip position is used to define the positioning of the tooltip
When the labelIconTooltip content is not provided, the label icon will be not shown. |
| — |
prefix Add a prefix to an input field |
| — |
suffix Add a suffix to an input field |
| — |
clearTestId Data testid for the clear button |
| "clear-btn-test-id" |
ref |
| — |
key |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |