Input

core package3.2.2

Note: All components shown on this site are supported by the Constellation design system. To learn how to configure Theme Cosmos, visit Pega Community.

The Input component allows users to enter and edit a single line of free-form text, often within a Form. If you would like to allow for more than one line of text input, we suggest using the TextArea component instead.

Usage

Any keyboard text may be entered into the Input component, including numbers and symbols. The type of the Input will affect how its contents are rendered or validated. All of the types align with the native HTML input types, though we do recommend using other Constellation components for most types. Refer to the table below to determine which component is best used for each supported type:

Inputs can be controlled or uncontrolled components. For a controlled component, make use of the value and onChange props. For an uncontrolled component, use the defaultValue prop. The Input component allows for standard Form Field structures such as being set required, disabled, or readOnly, as well as including a label, status, or info. They also support the use of actions which, if provided, will render an inline MenuButton containing the set of specified actions to configure the Input.

If there is a label and the Field is not disabled, passing an object to the additionalInfo prop that includes a heading and content will provide the user with more useful information on the Field when they click on the associated information Icon.

Example

Enter some value

Suggested values

If an onResolveSuggestion callback function is provided, and the status is set to pending, the user will be prompted to accept or deny whatever suggested value populates the Input.

Example

Accept AI suggestion?Either press Enter to accept the AI suggestion or edit the value to reject it

Related components

Properties

NameDescriptionDefaultType
actionsPass an array of Action objects to append button(s) inline with the Input.Action[]
additionalInfoButton when clicked will show additional information on a field
{
  content: string | Element;
  heading: string;
}
classNameAdditional CSS classes.string
defaultValueIf you wish to use an uncontrolled input, pass a defaultValue prop and a ref to access the input's native value prop or by other DOM ref means.string
disabledDisable the control. The browser defaults to false.boolean
idSets DOM id for the control and associates label element via 'for' attribute. If an id is not pass, a random id will be generated for any render.string
infoIt is recommended to pass a simple string to offer guidance. Text will be styled based on status prop.ReactNode
labelPass a string or a fragment with an Icon and string.ReactNode
labelHiddenVisually hides the label region.boolean
nameSets html name attribute for the underlying control. Useful for mapping to a data field.string
onResolveSuggestion(accepted: boolean) => void
placeholderPlaceholder text. The browser defaults to an empty string.string
readOnlyEnables read only modeboolean
requiredIndicate if the field is required. The browser defaults to false.boolean
statusSet visual state based on a validation state.
'error' |'pending' |'success' |'warning' 
typeSpecifies the type of input to be used."text"
'number' |'search' |'password' |'url' |'color' |'hidden' |'time' |'text' |'month' |'week' |'tel' |'email' |'date' |'datetime-local' 
valueCreates a controlled input and sets the value. Requires an onChange handler to update value. value + onChange is the recommended method per React team.string

Custom theming

You can override the styles of the Input component by setting a custom theme on the Configuration component.

Example

Enter some value

Theme properties

{
      •       height: '2rem',
      •       padding: 'components.form-control.padding', // → components.form-control.padding
      •       'background-color': 'components.form-control.background-color', // → components.form-control.background-color
      •       'border-color': 'components.form-control.border-color', // → components.form-control.border-color
      •       'border-width': 'components.form-control.border-width', // → components.form-control.border-width
      •       'border-radius': 'components.form-control.border-radius' // → components.form-control.border-radius
      •     }
    •   }
}