InputField
A configurable InputField component used to gather user input through a text field.
Import
- React
- Angular
- Vue.js
// with @dhl-official/react-library:
import { DhlInputField } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlInputField } from "@dhl-official/ui-libraries/react-library"
If the DUIL has been installed, you can use the web component directly:
<dhl-input-field></dhl-input-field>
// with @dhl-official/vue-library:
import { DhlInputField } from "@dhl-official/vue-library"
// with @dhl-official/ui-libraries/vue-library:
import { DhlInputField } from "@dhl-official/ui-libraries/vue-library"
Code
- React
- Angular
- Vue.js
<DhlInputField
variant={{
label: 'Label',
placeholder: 'Placeholder',
}}
></DhlInputField>
<dhl-input-field
[variant]="{
label: 'Label',
placeholder: 'Placeholder',
}"
></dhl-input-field>
<dhl-input-field
:variant.prop="{
label: 'Label',
placeholder: 'Placeholder',
}"
></dhl-input-field>
Interactive Demo
Examples with prefix / suffix addon
Example 1
Addon type: "prefix"
Code example
<DhlInputField
variant={{
label: "Label",
placeholder: "Placeholder",
}}
addon={{
type: "prefix",
label: "Unit"
}}
/>
Example 2
Addon type: "suffix" with options, colorVariant: "gray", validation type: "valid"
Code example
<DhlInputField
variant={{
label: "Label",
placeholder: "Placeholder",
}}
addon={{
type: "suffix",
label: "Unit",
colorVariant: ColorVariants.gray
}}
validation={{
type: "valid",
message: "Validation message"
}}
/>
Example 3
Addon type: "prefix" with options
Code example
<DhlInputField
variant={{
label: "Label",
placeholder: "Placeholder",
}}
addon={{
type: "prefix",
label: "Unit",
colorVariant: ColorVariants.white,
options: [
{
label: "g",
value: "g"
},
{
label: "kg",
value: "kg"
},
{
label: "oz",
value: "oz"
},
{
label: "lb",
value: "lb"
},
],
}}
/>
Example 4
Addon type: "suffix" with options, colorVariant: "gray", validation type: "invalid"
Code example
<DhlInputField
variant={{
label: "Label",
placeholder: "Placeholder",
}}
addon={{
type: "suffix",
label: "Unit",
colorVariant: ColorVariants.gray,
options: [
{
label: "g",
value: "g"
},
{
label: "kg",
value: "kg"
},
{
label: "oz",
value: "oz"
},
{
label: "lb",
value: "lb"
},
],
}}
validation={{
type: "invalid",
message: "Validation message"
}}
/>
Examples with Number Input Validation
The maxDigits and decimalPoint props only work when type="number". These props are designed specifically for numeric input validation and will have no effect on other input types.
Example: Limiting Integer Digits
Using maxDigits to limit the number of digits before the decimal point (e.g., max 5 digits):
Code example
<DhlInputField
type="number"
maxDigits={5}
variant={{
label: "Amount (Max 5 digits)",
placeholder: "Enter amount",
}}
/>
Example: Limiting Decimal Places
Using decimalPoint to limit decimal places (e.g., 2 decimal places for currency):
Code example
<DhlInputField
type="number"
decimalPoint={2}
variant={{
label: "Price (2 decimals)",
placeholder: "Enter price",
}}
/>
Example: Combining Both Validations
Combining maxDigits and decimalPoint for precise control (e.g., max 6 digits, 2 decimals):
Code example
<DhlInputField
type="number"
maxDigits={6}
decimalPoint={2}
variant={{
label: "Price (Max 6 digits, 2 decimals)",
placeholder: "Enter price",
}}
/>
Example: Block Decimals Entirely
Using decimalPoint={0} to prevent decimal input (integers only):
Code example
<DhlInputField
type="number"
decimalPoint={0}
variant={{
label: "Quantity (Integers only)",
placeholder: "Enter quantity",
}}
/>
Decimal Separator Configuration
When using type="number" with decimal values, you can configure the decimal separator using the decimalSeparator prop. This is useful for accommodating different locale preferences (e.g., European format uses comma, US format uses dot).
European Format (Comma Separator)
Code example
<DhlInputField
type="number"
decimalPoint={2}
decimalSeparator=","
variant={{
label: "Price (EUR)",
placeholder: "e.g., 123,45",
}}
/>
US Format (Dot Separator)
Code example
<DhlInputField
type="number"
decimalPoint={2}
decimalSeparator="."
variant={{
label: "Price (USD)",
placeholder: "e.g., 123.45",
}}
/>
Key Features:
- When
decimalSeparatoris set, the input automatically usestype="text"internally to avoid browser validation issues - Users can type either comma or dot, and the value is automatically normalized to the configured separator
- The normalized value is what gets submitted with the form
- Works together with
decimalPointandmaxDigitsprops to limit decimal places and integer digits
Readme
Usage
Dhl-input-field
Snippets of code in HTML and JavaScript to show some of the use cases for the component.
The code is not meant to be executed, but to be used as a reference for the usage of the component.
Angular, React and Vue usages are not included in this documentation, but can be easily derived from the html and javascript code.