Vivid API

Text Field

The Text Field component is used to allow users to provide text input when the expected input is short. As well as plain text, Text Field supports various types of text, including passwords, email addresses and telephone numbers.

Usage

Types

While Text Field follows the W3C specifictation, it only supports the following types:

text (default), email, password, search, tel, url

We support the following other types with the following components:

Input modes

Along with picking the correct type for the Text Field’s purpose, it’s also good for user experience to pick the correct inputmode.

The inputmode attribute hints at the type of data that might be entered by the user. This allows a browser to display an appropriate virtual keyboard.

Slots

Action Items Slot

Use the action-items slot to postfix elements to the Text Field input element.
In the example below Buttons are added to implement a custom funcationality for a search field.

Leading Action Items Slot

Use the leading-action-items slot to prefix elements to the Text Field input element.
In the example below a Select is added to implement a category filtered search field.

Helper Text Slot

The helper-text slot allows you to use rich content as the text-field’s helper text.

Contextual-Help

The contextual-help slot allows you to add the Contextual Help component next to the label.

API Reference

Properties

PropertyTypeDefaultDescription
appearance'fieldset' | 'ghost'
autoCompletestring
autofocusbooleanIndicates that an element should be focused on page load, or when the Dialog that it is part of is displayed
charCountbooleanUse in combination with `maxlength` to display a character count.
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
errorTextstringProvides a custom error message. Any current error state will be overridden.
helperTextstringProvides additional information to help the user enter the correct information. To add HTML to the helper text, use the helper-text slot instead.
initialValuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
inputModestringHints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.
labelstringThe label for the form element.
liststringValue of the id attribute of the `` of autocomplete options
maxlengthnumberMaximum length (number of characters) of `value`
minlengthnumberMinimum length (number of characters) of `value`
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
patternstringPattern the `value` must match to be valid
placeholderstringText that appears in the input element when it has no value set
readOnlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
scale'condensed' | 'normal'Sets the display size of the input element
shape'rounded' | 'pill'
sizenumberSize (in chars) of the input element
spellcheckbooleanControls whether or not to enable spell checking for the input field, or if the default spell checking configuration should be used.
successTextstringProvides a custom success message. Any current error state will be overridden.
type'text' | 'email' | 'password' | 'tel' | 'url'Allows setting a type or mode of text.
value
(modelValue)
stringThe current value of the element.
PropertyTypeDefaultDescription
appearance'fieldset' | 'ghost'
autocompletestring
autofocusbooleanIndicates that an element should be focused on page load, or when the Dialog that it is part of is displayed
char-countbooleanUse in combination with `maxlength` to display a character count.
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
error-textstringProvides a custom error message. Any current error state will be overridden.
helper-textstringProvides additional information to help the user enter the correct information. To add HTML to the helper text, use the helper-text slot instead.
valuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
inputmodestringHints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.
labelstringThe label for the form element.
liststringValue of the id attribute of the `` of autocomplete options
maxlengthnumberMaximum length (number of characters) of `value`
minlengthnumberMinimum length (number of characters) of `value`
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
patternstringPattern the `value` must match to be valid
placeholderstringText that appears in the input element when it has no value set
readonlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
scale'condensed' | 'normal'Sets the display size of the input element
shape'rounded' | 'pill'
sizenumberSize (in chars) of the input element
spellcheckbooleanControls whether or not to enable spell checking for the input field, or if the default spell checking configuration should be used.
success-textstringProvides a custom success message. Any current error state will be overridden.
type'text' | 'email' | 'password' | 'tel' | 'url'Allows setting a type or mode of text.
current-valuestringThe current value of the element.

Slots

NameDescription
action-itemsUsed to add action items to the end of the text-field.
contextual-helpSlot for the contextual-help component, displayed next to the label.
helper-textDescribes how to use the text-field. Alternative to the `helper-text` attribute.
iconThe preferred way to add an icon to the component.
leading-action-itemsUsed to add action items to the start of the text-field.
NameDescription
action-itemsUsed to add action items to the end of the text-field.
contextual-helpSlot for the contextual-help component, displayed next to the label.
helper-textDescribes how to use the text-field. Alternative to the `helper-text` attribute.
iconThe preferred way to add an icon to the component.
leading-action-itemsUsed to add action items to the start of the text-field.

Events

NameTypeDescription
changeCustomEvent<undefined>Fires a custom 'change' event when the value has changed
inputCustomEvent<undefined>Fires a custom 'input' event when the value has changed
NameTypeDescription
changeCustomEvent<undefined>Fires a custom 'change' event when the value has changed
inputCustomEvent<undefined>Fires a custom 'input' event when the value has changed

Methods

NameParamsReturnsDescription
checkValiditybooleanReturn the current validity of the element.
focusvoid
reportValiditybooleanReturn the current validity of the element. If false, fires an invalid event at the element.
selectvoidSelects all the text in the text field
validatevoid{@inheritDoc (FormAssociated:interface).validate}