Expand commentComment on line R9Resolved

Amount input

Amount inputs are fields specifically designed to capture and display monetary or amount-based numeric values in a structured, readable, and accessible format.

Props

NameTypeDescriptionDefault
alignment'left' | 'right'Sets the alignment inside the input.-
ariaLabelstringSpecifies a string to be used as the name for the textInput element when no label is provided.-
clearablebooleanIf true, the input will have an action to clear the entered value.-
config
{ thousandSeparator?: string; decimalSeparator?: string; symbolPosition?: 'before' | 'after'; } & ( | { currencyConfig?: { currency: string; currencyDisplay?: 'code' | 'symbol' | 'narrowSymbol' | 'name'; currencySign?: 'standard' | 'accounting'; }; unitsConfig?: never; } | { currencyConfig?: never; unitsConfig?: { unit: string; unitDisplay?: 'short' | 'long' | 'narrow'; }; } )
Configuration for the amount input, including currency or units, and formatting options such as thousand and decimal separators and the position of the currency symbol. currencyConfig and unitsConfig are mutually exclusive. To better understand the allowed values for currencies and units, please refer to the respective documentation.-
defaultValuestringInitial value of the input, only when it is uncontrolled.-
disabledbooleanIf true, the component will be disabled.-
errorstringIf it is a defined value and also a truthy string, the component will change its appearance, showing the error below the input component. If the defined value is an empty string, it will reserve a space below the component for a future error, but it would not change its look. In case of being undefined or null, both the appearance and the space for the error message would not be modified.-
helperTextstringHelper text to be placed above the input.-
labelstringText to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions.-
maxValuenumberSpecifies the maximum value allowed in the input.-
minValuenumberSpecifies the minimum value allowed in the input.-
namestringName attribute of the input element.-
numberOfDecimalsnumberSpecifies the number of decimal places allowed in the input. By default it is set to 3 or the permitted amount by the currency.-
numberOfIntegersnumberSpecifies the number of integer places allowed in the input.-
onBlur(val: { value: string; error?: string }) => voidThis function will be called when the input element loses the focus. An object including the input value and the error (if the value entered is not valid) will be passed to this function. If there is no error, error will not be defined.-
onChange(val: { value: string; error?: string }) => voidThis function will be called when the user types within the input element of the component. An object including the current value and the error (if the value entered is not valid) will be passed to this function. If there is no error, error will not be defined.-
optionalbooleanIf true, the input will be optional, showing '(Optional)' next to the label. Otherwise, the field will be considered required and an error will be passed as a parameter to the onBlur and onChange functions when it has not been filled.-
placeholderstringText to be put as placeholder of the input.-
readOnlybooleanIf true, the component will not be mutable, meaning the user can not edit the control. In addition, the clear action will not be displayed even if the flag is set to true.-
refReact.Ref<HTMLInputElement>Ref to the input element.-
size'small' | 'medium' | 'large' | 'fillParent'Size of the component.-
tabIndexnumberValue of the tabindex attribute.-
valuestringValue of the input. If undefined, the component will be uncontrolled and the value will be managed internally by the component.-

Examples

Controlled

() => {
  const [value, setValue] = useState("");
  
  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcAmountInput
        label="Enter your amount"
        value={value}
        onChange={({value}) => setValue(value)}
      />
    </DxcInset>
  );
}

Currency

() => {
  const config = {
    currencyConfig: {
      currency: "USD",
    },
  };
  
  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcAmountInput
        label="Enter your income"
        config={config}
      />
    </DxcInset>
  );
}

Unit

() => {
  const config = {
    unitsConfig: {
      unit: "kilogram",
      unitDisplay: "short",
    },
  };
  
  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcAmountInput
        label="Enter your weight"
        config={config}
      />
    </DxcInset>
  );
}