Skip to content

Textfield

<tpg-text-field></tpg-text-field>

Basic usage

Text fields allows users to enter text into the UI; can contain aiding icons. When used in a Logic Group, the Position variants (Left, Middle, Right) should be used to visually group the content together.

Examples

Types

Use the type attribute to set the textfields’s type.

Setting icons

Use the leading-icon-template and trailing-icon-template attributes to set icons.

Message

Alert users with the message attribute

Counter

Use the counter attribute to add a counter.

Note: we do not prevent the user from inputting more text should number of characters exceed the counter limit.

Clear text

Use the clear-button attribute to add a button that clears the text. Pressing the clear-button causes the Textfield to emit a TpgChangeEvent.

Unit of measurement

Use the uom attribute to add a Unit of Measurement.

States

The Textfield is enabled by default, but it can be set to disabled or read-only using the corresponding attributes.

Handling events

The Textfield emits a TpgInputEvent whenever it receives input from a user, TpgChangeEvent when value is cleared using the Clear Button, and TpgBlurEvent whenever the Textfield loses focus. Below are some basic examples of how these events are handled

Tables

Properties

Attribute Property Description Type Default Value
label label Textual label of the textfield string ''
uom uom Textual label of the textfield's UOM string ''
placeholder placeholder Optional placeholder that is visible if message is empty string ''
value value The value of the textfields input element string ''
counter counter Adds a counter that keeps track of how many characters are present in value property. number 0
type type The type of textfield to render in terms of severity-level. 'default' | 'error' | 'warning' | 'danger' 'default'
disabled disabled Flag that disables the textfield boolean false
read-only readOnly Flag that makes the textfield readOnly boolean false
clear-button clearButton Flag that includes a button to clear the text if included boolean false
leading-icon-template leadingIconTemplate URI-encoded SVG template for the button's icon. Supported constants are found in IconConstant | '' ''
trailing-icon-template trailingIconTemplate URI-encoded SVG template for the button's icon. Supported constants are found in IconConstant | '' ''
message message Message to appear on badge if set. string ''
input-type inputType Specifies the type of the underlying HTML <input> element. 'text' | 'password' | 'number' | 'date' 'text'
truncate truncate boolean false
form-associated formAssociated boolean true
name name name property for use in conjunction with html forms string

Events

Event name Reactjs attribute Description
tpg-input ontpg-input Event emitted when text-field receives input while not disabled or readonly. Contains the new input value.
tpg-blur ontpg-blur Event emitted When the text-field loses focus
tpg-focus ontpg-focus Event emitted When the text-field loses focus
tpg-change ontpg-change Event fired when clear button is pressed

Functions

Name Description Arguments
focus This method can be called to shift focus to the input field managed by the textfield. No parameters
blur This method can be called to unfocus the input field managed by the textfield. No parameters
scroll This method can be used to control the scroll of the input.
  • options: ScrollToOptions
scroll
  • x: number
  • y: number
scroll
  • arg1: ScrollToOptions | number
  • arg2: number

Slots

Name Description
No slots found.

CSS Parts

Attribute Description
No CSS parts found.

Sandbox