#Overview
Input Fields are used with Forms (Code).
#Text Field
Show codeHide code
export const TextFieldDemo = () => {
const form = useForm<{ textField: string }>();
return (
<form onSubmit={form.handleSubmit(() => {})}>
<TextField
form={form}
name="textField"
label="A text between 10 and 50 characters"
options={{
required: {
value: true,
message: "Please provide a text between 10 and 50 characters",
},
minLength: {
value: 10,
message:
"Choose a text that is equal or longer than 10 characters.",
},
maxLength: {
value: 50,
message: "Choose a text that is shorter or equal to 50 characters.",
},
}}
/>
<Button type="submit">Submit</Button>
</form>
);
};
Name | Type | Default | Description |
---|---|---|---|
form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
name * | TFieldName | - | The name of the input being registered from the form |
defaultValue | number | string | - | The default value of the input field |
disabled | boolean | - | If true, the input field is disabled |
hasError | boolean | - | If true, turns the border red |
helpText | ReactNode | - | A help text that can be displayed below the input field |
hideHelpAndValidation | boolean |
| Hides the help text and validation message |
iconAfter | FunctionComponent<IIconProps> | - | The icon after the input text |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text |
label | ReactNode | - | The label of the input field |
labelOptionalAppendix | ReactNode | - | Marker inside the label, when the field is optional |
labelRequiredAppendix | ReactNode | - | Marker inside the label, when the field is required |
noWrap | boolean | - | |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler |
options | TBase extends unknown ? Omit<TBase, TKey> : never |
| The options that can be set for the registration of the field |
placeholder | string | - | A hint for the expected value |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field |
#Multi Line Text Field
Field for several lines of text.
Show codeHide code
export const MultiLineTextFieldDemo = () => {
const form = useForm<{ textField: string }>();
const maxLength = 300;
const [currentLength, setCurrentLength] = useState(0);
return (
<form onSubmit={form.handleSubmit(() => {})}>
<MultiLineTextField
form={form}
name="textField"
label="Long text with limit"
helpText={`${currentLength}/${maxLength} Characters`}
onChange={(e) => setCurrentLength(e.target.value.length || 0)}
options={{
required: { value: true, message: "Value is required" },
maxLength: {
value: maxLength,
message: `${currentLength}/${maxLength} Characters`,
},
}}
/>
<Button type="submit">Submit</Button>
</form>
);
};
Name | Type | Default | Description |
---|---|---|---|
form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
name * | TFieldName | - | The name of the input being registered from the form |
defaultValue | string | - | The default value of the input field |
disabled | boolean | - | If true, the input field is disabled |
hasError | boolean | - | If true, turns the border red |
helpText | ReactNode | - | A help text that can be displayed below the input field |
hideHelpAndValidation | boolean |
| Hides the help text and validation message |
label | ReactNode | - | The label of the input field |
labelOptionalAppendix | ReactNode | - | Marker inside the label, when the field is optional |
labelRequiredAppendix | ReactNode | - | Marker inside the label, when the field is required |
noWrap | boolean | - | |
onChange | ChangeEventHandler<HTMLTextAreaElement> | - | The change event handler |
options | TBase extends unknown ? Omit<TBase, TKey> : never |
| The options that can be set for the registration of the field |
placeholder | string | - | A hint for the expected value |
rows | number |
| The initial amount of visible lines |
#Number and Decimal Field
Fields to either enter a numeric or a decimal value.
The input mode is changed fore these fields but is not set intentionally as it locks the keyboard
and blocks feedback for typing characters. Validation should always give feedback and users should be allowed to type freely.type="number"
Show codeHide code
export const NumberTextFieldDemo = () => {
const form = useForm<{ textField: string }>();
return (
<form onSubmit={form.handleSubmit(() => {})} noValidate>
<NumberTextField
form={form}
name="textField"
label="A number between 2 and 10"
options={{
required: {
value: true,
message: "Please provide a number between 2 and 10",
},
min: {
value: 2,
message: "Choose a number that is greater or equal to 2.",
},
max: {
value: 10,
message: "Choose a number, that is smaller or equal to ten.",
},
}}
/>
<Button type="submit">Submit</Button>
</form>
);
};
Show codeHide code
export const DecimalTextFieldDemo = () => {
const form = useForm<{ textField: string }>();
return (
<form onSubmit={form.handleSubmit(() => {})} noValidate>
<DecimalTextField
step={0.05}
form={form}
name="textField"
label="A number between 0 and 1"
options={{
required: {
value: true,
message: "Please provide a number between 0 and 1",
},
min: {
value: 0,
message: "Choose a number that is greater or equal to 0.",
},
max: {
value: 1,
message: "Choose a number, that is smaller or equal to 1.",
},
}}
/>
<Button type="submit">Submit</Button>
</form>
);
};
#Phone Number Text Field
Accessibility complete and browser auto-fill ready phone number field. With international phone number validation.
Show codeHide code
export const PhoneNumberTextFieldDemo = () => {
const form = useForm<{ phoneNumber?: string }>({ mode: "onBlur" });
return (
<form onSubmit={form.handleSubmit(() => {})}>
<PhoneNumberTextField
form={form}
name="phoneNumber"
options={{ required: false }}
/>
<Button type="submit">Submit</Button>
</form>
);
};
#Checked Text Field
Built-in visual representation of valid input, through a checkmark, when the field was touched and validates.
When setting up the form, set the mode
to
onBlur
, onChange
, onTouched
or all
.
Otherwise the field will display a checkmark once the field is touched
but may be invalidated once the user tries to submit the form.
Show codeHide code
export const CheckedTextFieldDemo = () => {
const form = useForm<{ email: string }>({ mode: "onBlur" });
return (
<form onSubmit={form.handleSubmit(() => {})}>
<CheckedTextField
form={form}
name="email"
label="Email"
options={{
required: { value: true, message: "Value is required" },
pattern: {
value: /\S+@\S+\.\S+/,
message: "Please provide a valid email address",
},
}}
/>
<Button type="submit">Submit</Button>
</form>
);
};
Name | Type | Default | Description |
---|---|---|---|
form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
name * | TFieldName | - | The name of the input being registered from the form |
defaultValue | number | string | - | The default value of the input field |
disabled | boolean | - | If true, the input field is disabled |
hasError | boolean | - | If true, turns the border red |
helpText | ReactNode | - | A help text that can be displayed below the input field |
hideHelpAndValidation | boolean |
| Hides the help text and validation message |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text |
label | ReactNode | - | The label of the input field |
labelOptionalAppendix | ReactNode | - | Marker inside the label, when the field is optional |
labelRequiredAppendix | ReactNode | - | Marker inside the label, when the field is required |
noWrap | boolean | - | |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler |
options | TBase extends unknown ? Omit<TBase, TKey> : never |
| The options that can be set for the registration of the field |
placeholder | string | - | A hint for the expected value |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field |
#Checked Autocomplete Text Field
The Checked Autocomplete Text Field lets you select a suggestion based on your input.
When registering the form, use the same mode
as suggested for the Checked Text Field.
Read Dropdown (Code) to understand how suggestion items can be added to the field.
Show codeHide code
export const CheckedAutocompleteTextFieldDemo = () => {
const form = useForm<{ fruits: string }>();
return (
<form onSubmit={form.handleSubmit(() => {})}>
<CheckedAutocompleteTextField
form={form}
name="fruits"
label="Favourite Fruit"
items={fruitOptions}
minCharactersForSuggestion={1}
options={{
required: {
value: true,
message: "Please provide a value",
},
}}
/>
<Button type="submit">Send</Button>
</form>
);
};
Name | Type | Default | Description |
---|---|---|---|
form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
items * | Array<ISelectOption> | - | The selectable items |
name * | TFieldName | - | The name of the input being registered from the form |
defaultValue | number | string | - | The default value of the input field |
disabled | boolean | - | If true, the input field is disabled |
hasError | boolean | - | If true, turns the border red |
helpText | ReactNode | - | A help text that can be displayed below the input field |
hideHelpAndValidation | boolean | - | Hides the help text and validation message |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text |
itemToString | (item: ISelectOption) => string |
| Parse function to convert the selected into into a string to show inside the input field |
label | ReactNode | - | The label of the input field |
labelOptionalAppendix | ReactNode | - | Marker inside the label, when the field is optional |
labelRequiredAppendix | ReactNode | - | Marker inside the label, when the field is required |
minCharactersForSuggestion | number |
| The minimal amount of characters needed to show suggestions |
noWrap | boolean | - | |
onBlur | ChangeEventHandler<HTMLInputElement> | - | Callback the input field is blurred |
onChange | ChangeEventHandler<HTMLInputElement> | - | Callback when the selected item changes and when input changes |
onInputValueChange | (inputValue: string) => Promise<void> | - | An optional callback to filter items asynchronous - useful to fetch an API again |
onMenuClose | () => void | - | Callback when the menu closes |
onMenuOpen | () => void | - | Callback when the menu opens |
onSelect | ChangeEventHandler<HTMLInputElement> | - | Callback when the selected item changes |
options | TBase extends unknown ? Omit<TBase, TKey> : never |
| The options that can be set for the registration of the field |
placeholder | string | - | A hint for the expected value |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field |
#Max Length Text Field
A Text Field and Multi Line Text Field that will show a character count once a user types 85% of the allowed number of characters. It will show a validation error if the form is validated and the max length is exceeded.
Show codeHide code
export const MaxLengthTextFieldDemo = () => {
const form = useForm<{ text: string }>({
defaultValues: { text: "Some existing text" },
});
return (
<form onSubmit={form.handleSubmit(() => {})}>
<MaxLengthTextField form={form} name="text" maxLength={70} />
<Button type="submit">Submit</Button>
</form>
);
};
Show codeHide code
export const MaxLengthMultiLineTextFieldDemo = () => {
const form = useForm<{ text: string }>({ mode: "onSubmit" });
return (
<form onSubmit={form.handleSubmit(() => {})}>
<MaxLengthMultiLineTextField form={form} name="text" maxLength={200} />
<ButtonGroup>
<Button onClick={() => form.reset()}>Reset</Button>
<Button variant="primary" type="submit">
Submit
</Button>
</ButtonGroup>
</form>
);
};
#Outside of forms
#Input Field
Name | Type | Default | Description | Controls |
---|---|---|---|---|
defaultValue | number | string | - | The default value of the input field | |
disabled | boolean | - | If true, the input field is disabled | |
hasError | boolean | - | If true, turns the border red | |
iconAfter | FunctionComponent<IIconProps> | - | The icon after the input text | |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text | |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
placeholder | string | - | A hint for the expected value | |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field | |
value | number | string | - | The value of the input field |
#Multi Line Input Field
Name | Type | Default | Description | Controls |
---|---|---|---|---|
defaultValue | string | - | The default value of the input field | |
disabled | boolean | - | If true, the input field is disabled | |
hasError | boolean | - | If true, turns the border red | |
onChange | ChangeEventHandler<HTMLTextAreaElement> | - | The change event handler | - |
placeholder | string | - | A hint for the expected value | |
rows | number |
| The initial amount of visible lines | |
value | string | - | The value of the input field |
#Checked Input Field
Checked Input Fields add a Checkmark at the end of the field to make it more obvious that the validation was successful.
Name | Type | Default | Description | Controls |
---|---|---|---|---|
isChecked * | boolean | - | If true, a checkmark at the end of the field is displayed | |
defaultValue | number | string | - | The default value of the input field | |
disabled | boolean | - | If true, the input field is disabled | |
hasError | boolean | - | If true, turns the border red | |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text | - |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
placeholder | string | - | A hint for the expected value | |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field | |
value | number | string | - | The value of the input field |
#Checked Autocomplete Input Field
The Checked Autocomplete Input Field lets you select a suggestion based on your input. Additionally, it adds a Checkmark at the end of the field to make it more obvious that the validation was successful.
Name | Type | Default | Description | Controls |
---|---|---|---|---|
isChecked * | boolean | - | If true, a checkmark at the end of the field is displayed | |
items * | Array<ISelectOption> | - | The selectable items | - |
defaultValue | number | string | - | The default value of the input field | |
disabled | boolean | - | If true, the input field is disabled | |
hasError | boolean | - | If true, turns the border red | |
iconBefore | FunctionComponent<IIconProps> | - | The icon before the input text | - |
itemToString | (item: ISelectOption) => string |
| Parse function to convert the selected into into a string to show inside the input field | - |
minCharactersForSuggestion | number |
| The minimal amount of characters needed to show suggestions | |
onBlur | ChangeEventHandler<HTMLInputElement> | - | Callback the input field is blurred | - |
onChange | ChangeEventHandler<HTMLInputElement> | - | Callback when the selected item changes and when input changes | - |
onInputValueChange | (inputValue: string) => Promise<void> | - | An optional callback to filter items asynchronous - useful to fetch an API again | - |
onMenuClose | () => void | - | Callback when the menu closes | - |
onMenuOpen | () => void | - | Callback when the menu opens | - |
onSelect | ChangeEventHandler<HTMLInputElement> | - | Callback when the selected item changes | - |
placeholder | string | - | A hint for the expected value | |
type | "email" | "number" | "password" | "search" | "tel" | "text" | "url" |
| Set the type of input field | |
value | string | - | The value of the input field |
#Colors
- Token
CHECKMARK
#280#8d6#1a3#4c4FIELD_BACKGROUND
#fff#111#fff#111FIELD_BACKGROUND_DISABLED
#0000#fff1#0000#fff1FIELD_BACKGROUND_ERROR
#fff#111#fff#111FIELD_BACKGROUND_FILLED
#fff#111#fff#111FIELD_BACKGROUND_FOCUS
#fff#111#fff#111FIELD_BORDER
#bbb#fff4#bbb#fff4FIELD_BORDER_DISABLED
#0001#fff1#0001#fff1FIELD_BORDER_ERROR
#f75#f75#e02#f55FIELD_BORDER_FILLED
#bbb#fff4#bbb#fff4FIELD_BORDER_FOCUS
#555#fff#059#fffHELP_TEXT
#0009#fffb#0009#fffbHELP_TEXT_DISABLED
#0009#fffb#0009#fffbHELP_TEXT_ERROR
#c42#f75#e02#f44HELP_TEXT_FILLED
#0009#fffb#0009#fffbHELP_TEXT_FOCUS
#0009#fffb#0009#fffbICONAFTER_BACKGROUND
#000d#fffb#000d#fffbICONAFTER_BACKGROUND_DISABLED
#0004#fff4#0004#fff4ICONAFTER_BACKGROUND_ERROR
#000d#fffb#000d#fffbICONAFTER_BACKGROUND_FILLED
#000d#fffb#000d#fffbICONAFTER_BACKGROUND_FOCUS
#000d#fffb#000d#fffbICONAFTER_FIELD_BACKGROUND_DISABLED
#fff#111#fff#111ICONBEFORE_BACKGROUND
#000d#fffb#000d#fffbICONBEFORE_BACKGROUND_DISABLED
#0004#fff4#0004#fff4ICONBEFORE_BACKGROUND_ERROR
#000d#fffb#000d#fffbICONBEFORE_BACKGROUND_FILLED
#000d#fffb#000d#fffbICONBEFORE_BACKGROUND_FOCUS
#000d#fffb#000d#fffbLABEL_TEXT
#0009#fffb#0009#fffbLABEL_TEXT_DISABLED
#0009#fffb#0009#fffbLABEL_TEXT_ERROR
#0009#fffb#0009#fffbLABEL_TEXT_FILLED
#0009#fffb#0009#fffbLABEL_TEXT_FOCUS
#0009#fffb#0009#fffbVALUE_TEXT
#0004#fff4#0004#fff4VALUE_TEXT_DISABLED
#0004#fff4#0004#fff4VALUE_TEXT_ERROR
#000#fff#000#fffVALUE_TEXT_FILLED
#000#fff#000#fffVALUE_TEXT_FOCUS
#000#fff#000#fff