Input

Updated:

Use for single-line text entry including email, phone, currency, SSN, and password.

Properties

The q2-input element has one or more properties that support text localization. Those properties are indicated by the localizable badge in the description.

Learn more about properties.

autocapitalize

The autocapitalize attribute is an enumerated attribute that controls whether and how text input is automatically capitalized as it is entered/edited by the user.

See MDN for a list of supported values.

This attribute only affects the behavior of input mechanisms like virtual keyboards on mobile devices and voice input.

autocomplete

The HTML autocomplete attribute lets web developers specify what permission (if any) the user agent has to provide automated assistance in filling out form field values, as well as guidance to the browser as to the type of information expected in the field.

See MDN for a list of supported values.

autocorrect

A string that indicates whether or not to activate automatic correction while the user is editing this field.

This is currently only supported in Safari.

autofocus

Autofocus is enabled when the property is added to an element. To disable, remove attribute or set it to false. If applied to multiple elements, the first one will receive focus.

badgeTheme
badge-theme

The color of the badge when in the active state. The property badgeValue must be provided.

badgeValue
badge-value

Displays a q2-badge element on the right side of the input.

clearable

Renders an icon button when the field is non-empty. Pressing the button clears all input from the field.

current

If provided a value, it sets the aria-current attribute on the inner input. See MDN for more information on aria-current.

disabled

Indicates the field cannot be focused or interacted with.

errors

Each item in the errors array will appear below the input field when the field is focused.

Localizable
formatModifier
format-modifier

Defines the field's expected input format, and automatically masks user input to conform. Specific types support different modifier options. See the section on Format Modifiers for all available options.

hideLabel
hide-label

Hide's the field's <label> element from view.

Only use when a visible label is impractical.

hideMessages
hide-messages

When true and the input field has an active validation error, the field shows the error state without displaying associated error messages below the field (from the errors array). Primarily used for dropdown selects and date pickers whose controls appear below the input field (where the error messages, if displayed, would also appear).

hints

Each item in the hints array will appear below the input field when the field is focused.

The errors array takes precedence over the hints array. If an input field has both hints and errors, only the errors will display. Once all errors are resolved, the hints display the next time the field is focused.

Localizable
iconLeft
icon-left

Shows a left-aligned q2-icon within the field.

iconRight
icon-right

Shows a right-aligned q2-icon within the field.

label

The label that appears above the field. This is announced by screen readers when the field is focused.

Localizable
max

When present, it does not allow a value greater than max when the user uses the Up/Down arrow keys to change the value.

Only applicable when type="number".

maxlength

Defines the maximum allowed input length in characters. Formatting characters (e.g. ., -, etc) are included in the maxlength comparison. Make sure you account for them when setting the maxlength value. Input types that use masks have their own inherent maxlength.

min

When present, it does not allow a value less than the min when the user uses the Up/Down arrow keys to change the value.

Only applicable when type="number".

optional

Appends "(optional)" to the field label, and sets aria-required on the nested input tag to false.

pattern

Applies the value as a RegEx pattern to assess the validity of the input field's value. Check the ValidityState's patternMismatch property for the result.

Example:

<q2-input label="My input" pattern="[a-zA-Z0-9]{3,5}" id="myInput"></q2-input>
// enter "abcdefgh" in the input field (too many characters)
const myInput = document.querySelector('#myInput');
console.log(myInput.validity.patternMismatch); // true
placeholder

Text that appears within the field when it is blurred and empty. Placeholder text disappears when the user focuses on the field and provides input.

Primarily used for rare cases in which a visible form label is not expected (e.g., search fields).

Localizable
pseudo

Component will display as a clickable <button> styled to be identical to the default <input> field.

readonly

Appends "(read only)" to the field label, and field becomes unusable, but remains focusable. Takes priority over optional if both are true.

showCount
show-count

Shows a character counter above the input field to track the number of characters currently in the field. If maxlength is set, showCount displays the number of characters in relation the maxlength value.

showVisibilityToggle
show-visibility-toggle

Displays a toggle button at the end of the input field which shows or hides the actual value.

Only applicable when type is text, password, or ssn.

step

When present, it jumps the value in increments of step when the user uses the Up/Down arrow keys to change the value.

Only applicable when type="number".

textHidden
text-hidden

Controls visibility of the value when the type is text, password, or ssn. When the input type is password, it will default to true, hiding the text.

type

Specifies the field's expected input type, and provides the optimal keyboard on mobile devices.

valid

Displays a success state icon when the field does not have active errors.

validity

Returns a read-only ValidityState object representing the validity states of the element. See MDN for more information on ValidityState.

value

The value of the input field.

The visible value of formatted input fields may not match the element's value property. When setting an input's value programmatically (e.g. pre-populating a form), ensure that the supplied value is in a format that can be handled by its consuming logic. q2-input does not change its own value outside of its default change event handler.

In q2-input where type="currency"

  • element.value = 1234.56
  • visible value: $1,234.56

Events

The q2-input element exposes events that can be used to send and receive data from the component based on user interaction.

Learn more about events.

tctChange

Emitted when the field loses focus after the value has been changed.

Event Detail Type signature

EventDetail

If an event handler is bound to the element using:

  • ontctChange property - The default handler will not fire, and the value must be updated in the custom handler.
  • addEventListener("tctChange") method - The default handler will fire alongside the custom handler.

tctClear

Emitted when the field value is cleared. Emitted with { source: 'input' } when search text is cleared by keyboard. Emitted with { source: 'button' } when search text is cleared by clicking clear icon.

Event Detail Type signature

undefined

tctFormatted

Emitted when the field value is formatted.

Event Detail Type signature

FormatterValueObject

tctInput

Emitted when the field value is updated.

Event Detail Type signature

EventDetail

If an event handler is bound to the element using:

  • ontctInput property - The default handler will not fire, and the value must be updated in the custom handler.
  • addEventListener("tctInput") method - The default handler will fire alongside the custom handler.

tctInvalid

Emitted when the validation is updated.

Event Detail Type signature

EventDetail

If an event handler is bound to the element using:

  • ontctInvalid property - The default handler will not fire, and the value must be updated in the custom handler.
  • addEventListener("tctInvalid") method - The default handler will fire alongside the custom handler.

Methods

The q2-input element exposes methods that can be used to perform various actions on the component.

Learn more about methods.

checkValidity

Emulates firing checkValidity on <input>, emits invalid event if validation failed.

Type signature

checkValidity() => Promise<boolean>

clearValue

Test only

Emulates clicking the clear button when the input is clearable.

Type signature

clearValue() => Promise<void>

Only applicable when the input is clearable.

setValue

Test only

Emulates focusing the <input>, entering the provided value, and emitting an input event.

This method leaves the focus on the <input> and as a result does not trigger the change event. If you want to trigger the change event, move the focus to another element after calling this method.

Type signature

setValue(value: string) => Promise<void>

Slots

The q2-input element has multiple slots that can be used to insert custom content into the component.

Learn more about slots

An optional slot to display custom content in the input field.

An optional slot to add a Button on the left-hand side of the input field.

An optional slot to add a Button on the right-hand side of the input field.

An optional slot to display a custom label.

Development

Credit Card Format Iconography

The type credit-card input masking and iconography include Amex, Discover, Mastercard, Visa, and Dinersclub. Information about credit card number masks and shapes can be found in this Baymard credit card article.

Input Slots

In your use of q2-input you may experience the need to use a button instead of just a plain icon on the right or left side of the input field. For this reason, we've added two slots you may use to make this possible.

Left side: input-left

With this slot, you can add a button to the left-hand side of the q2-input field.

<q2-input label="My Input Field">
  <q2-btn slot="input-left">
    <q2-icon type="calculator">
    </q2-icon>
  </q2-btn>
</q2-input>
Right side: input-right

With this slot, you can add a button to the right-hand side of the q2-input field.

<q2-input label="My Input Field">
  <q2-btn slot="input-right">
    <q2-icon type="add">
    </q2-icon>
  </q2-btn>
</q2-input>

Label Slot

If you need to display a label with more complexity, you may use the label slot to do just that. It allows you to provide complex HTML markup while still resulting in semantic code. Here is an example of how you can use it:

Full Name
<q2-input>
  <div slot="label">
    Full Name
    <q2-tooltip label="First and last name" position="e">
      <q2-icon inline type="question"></q2-icon>
    </q2-tooltip>
  </div>
</q2-input>

Using checkValidity and pattern

Tecton aims to accurately replicate native browser APIs wherever possible. The checkValidity API can be somewhat tricky, so it's important to outline its expected behavior.

When you interact with the <q2-input> component, it updates the validity property in the same way a regular <input /> field does. However, if you need to check the validity at runtime, it's best to use the checkValidity method.

When you call checkValidity(), it returns a boolean value indicating whether the element is valid. If the input is in an invalid state, it will also emit an "invalid" event that you can listen for. From there, you can check the validity property of the component to access the corresponding validity object it provides.

<q2-input
  label="State Abbreviation"
  pattern="[A-Za-z]{2}"
></q2-input>

<q2-btn
  intent="workflow-secondary"
>
  Check Validity
</q2-btn>

<script>
  const myInput = document.querySelector("q2-input");
  const checkBtn = document.querySelector("q2-btn");

  checkBtn.addEventListener("click", async () => {
    await myInput.checkValidity();
  });

  myInput.addEventListener("invalid", async (result) => {
    console.log("VALIDITY", myInput.validity);
  });
</script>

Format Modifiers

Format modifiers control field behavior for different types of input fields. Each input type accepts its own set.

Alpha

Input Type: alpha

Spaces are disallowed by default; one modifier re-enables them.

format-modifier
Description
spaced
Allows spaces in the field.

Example:

<q2-input type="alpha" format-modifier="spaced"></q2-input>

Currency

Input Type: currency

Accepts float values for any supported currency code. Append -integer to a code to restrict entry to whole numbers.

format-modifier
Description
*-integer
Limits entry to integers only.

Example:

<q2-input type="currency" format-modifier="MX-integer"></q2-input>

Numeric and Percentage

Input Types: numeric, percentage

These types share the same modifiers: positive blocks negatives, delimited adds thousands separators, and Ndecimal allows N decimal places (e.g., 2decimal).

format-modifier
Allows Decimals
Examples
integer
No
100, 1000, -1000000
integer-delimited
No
100, 1,000, -1,000,000
integer-positive
No
100, 1000, 1000000
integer-delimited-positive
No
100, 1,000, 1,000,000
Ndecimal
Yes
With 2decimal: 100.00, 1000.00, -1000000.00
Ndecimal-delimited
Yes
With 2decimal-delimited: 100.00, 1,000.00, -1,000,000.00
Ndecimal-positive
Yes
With 2decimal-positive: 100.00, 1000.00, 1000000.00
Ndecimal-delimited-positive
Yes
With 2decimal-delimited-positive: 100.00, 1,000.00, 1,000,000.00

Example:

<q2-input type="numeric" format-modifier="4decimal-delimited"></q2-input>

Phone

Input Type: phone

Use the Alpha-2 country code to set the field's mask and dialing prefix.

format-modifier
Country
AC
Ascension Island
AD
Andorra
AE
United Arab Emirates
AF
Afghanistan
AG
Antigua & Barbuda
AI
Anguilla
AL
Albania
AM
Armenia
AO
Angola
AR
Argentina
AS
American Samoa
AT
Austria
AU
Australia
AW
Aruba
AX
Åland Islands
AZ
Azerbaijan
BA
Bosnia & Herzegovina
BB
Barbados
BD
Bangladesh
BE
Belgium
BF
Burkina Faso
BG
Bulgaria
BH
Bahrain
BI
Burundi
BJ
Benin
BL
St. Barthélemy
BM
Bermuda
BN
Brunei
BO
Bolivia
BQ
Caribbean Netherlands
BR
Brazil
BS
Bahamas
BT
Bhutan
BW
Botswana
BY
Belarus
BZ
Belize
CA
Canada
CC
Cocos (Keeling) Islands
CD
Congo - Kinshasa
CF
Central African Republic
CG
Congo - Brazzaville
CH
Switzerland
CI
Côte d'Ivoire
CK
Cook Islands
CL
Chile
CM
Cameroon
CN
China
CO
Colombia
CR
Costa Rica
CU
Cuba
CV
Cape Verde
CW
Curaçao
CX
Christmas Island
CY
Cyprus
CZ
Czechia
DE
Germany
DJ
Djibouti
DK
Denmark
DM
Dominica
DO
Dominican Republic
DZ
Algeria
EC
Ecuador
EE
Estonia
EG
Egypt
EH
Western Sahara
ER
Eritrea
ES
Spain
ET
Ethiopia
FI
Finland
FJ
Fiji
FK
Falkland Islands
FM
Micronesia
FO
Faroe Islands
FR
France
GA
Gabon
GB
United Kingdom
GD
Grenada
GE
Georgia
GF
French Guiana
GG
Guernsey
GH
Ghana
GI
Gibraltar
GL
Greenland
GM
Gambia
GN
Guinea
GP
Guadeloupe
GQ
Equatorial Guinea
GR
Greece
GT
Guatemala
GU
Guam
GW
Guinea-Bissau
GY
Guyana
HK
Hong Kong SAR China
HN
Honduras
HR
Croatia
HT
Haiti
HU
Hungary
ID
Indonesia
IE
Ireland
IL
Israel
IM
Isle of Man
IN
India
IO
British Indian Ocean Territory
IQ
Iraq
IR
Iran
IS
Iceland
IT
Italy
JE
Jersey
JM
Jamaica
JO
Jordan
JP
Japan
KE
Kenya
KG
Kyrgyzstan
KH
Cambodia
KI
Kiribati
KM
Comoros
KN
St. Kitts & Nevis
KP
North Korea
KR
South Korea
KW
Kuwait
KY
Cayman Islands
KZ
Kazakhstan
LA
Laos
LB
Lebanon
LC
St. Lucia
LI
Liechtenstein
LK
Sri Lanka
LR
Liberia
LS
Lesotho
LT
Lithuania
LU
Luxembourg
LV
Latvia
LY
Libya
MA
Morocco
MC
Monaco
MD
Moldova
ME
Montenegro
MF
St. Martin
MG
Madagascar
MH
Marshall Islands
MK
North Macedonia
ML
Mali
MM
Myanmar (Burma)
MN
Mongolia
MO
Macao SAR China
MP
Northern Mariana Islands
MQ
Martinique
MR
Mauritania
MS
Montserrat
MT
Malta
MU
Mauritius
MV
Maldives
MW
Malawi
MX
Mexico
MY
Malaysia
MZ
Mozambique
NA
Namibia
NC
New Caledonia
NE
Niger
NF
Norfolk Island
NG
Nigeria
NI
Nicaragua
NL
Netherlands
NO
Norway
NP
Nepal
NR
Nauru
NU
Niue
NZ
New Zealand
OM
Oman
PA
Panama
PE
Peru
PF
French Polynesia
PG
Papua New Guinea
PH
Philippines
PK
Pakistan
PL
Poland
PM
St. Pierre & Miquelon
PR
Puerto Rico
PS
Palestinian Territories
PT
Portugal
PW
Palau
PY
Paraguay
QA
Qatar
RE
Réunion
RO
Romania
RS
Serbia
RU
Russia
RW
Rwanda
SA
Saudi Arabia
SB
Solomon Islands
SC
Seychelles
SD
Sudan
SE
Sweden
SG
Singapore
SH
St. Helena
SI
Slovenia
SJ
Svalbard & Jan Mayen
SK
Slovakia
SL
Sierra Leone
SM
San Marino
SN
Senegal
SO
Somalia
SR
Suriname
SS
South Sudan
ST
São Tomé & Príncipe
SV
El Salvador
SX
Sint Maarten
SY
Syria
SZ
Eswatini
TA
Tristan da Cunha
TC
Turks & Caicos Islands
TD
Chad
TG
Togo
TH
Thailand
TJ
Tajikistan
TK
Tokelau
TL
Timor-Leste
TM
Turkmenistan
TN
Tunisia
TO
Tonga
TR
Türkiye
TT
Trinidad & Tobago
TV
Tuvalu
TW
Taiwan
TZ
Tanzania
UA
Ukraine
UG
Uganda
US
United States
UY
Uruguay
UZ
Uzbekistan
VA
Vatican City
VC
St. Vincent & Grenadines
VE
Venezuela
VG
British Virgin Islands
VI
U.S. Virgin Islands
VN
Vietnam
VU
Vanuatu
WF
Wallis & Futuna
WS
Samoa
XK
Kosovo
YE
Yemen
YT
Mayotte
ZA
South Africa
ZM
Zambia
ZW
Zimbabwe

Example:

<q2-input type="phone" format-modifier="SI"></q2-input>

Postal

Input Type: postal

Use the Alpha-2 country code, plus an optional variant suffix, to set the field's mask.

format-modifier
Country
AF
Afghanistan
AL
Albania
DZ
Algeria
AC
Ascension Island
AD
Andorra
AR
Argentina
AR+
Argentina
AI
Anguilla
AM
Armenia
AS
American Samoa
AS+4
American Samoa
AU
Australia
AT
Austria
AZ
Azerbaijan
BH
Bahrain
BD
Bangladesh
BB
Barbados
BY
Belarus
BE
Belgium
BM
Bermuda
BT
Bhutan
BA
Bosnia & Herzegovina
BR
Brazil
BR+3
Brazil
VG
British Virgin Islands
BN
Brunei
BG
Bulgaria
KH
Cambodia
KY
Cayman Islands
CA
Canada
CL
Chile
CN
China
CX
Christmas Island
CC
Cocos (Keeling) Islands
CO
Colombia
CR
Costa Rica
CR+4
Costa Rica
CV
Cape Verde
HR
Croatia
CU
Cuba
CY
Cyprus
CZ
Czechia
DK
Denmark
DO
Dominican Republic
EC
Ecuador
SV
El Salvador
EG
Egypt
EE
Estonia
ET
Ethiopia
FK
Falkland Islands
FO
Faroe Islands
FI
Finland
FR
France
GF
French Guiana
PF
French Polynesia
GI
Gibraltar
GE
Georgia
DE
Germany
GR
Greece
GL
Greenland
GP
Guadeloupe
GU
Guam
GU+4
Guam
GT
Guatemala
GG
Guernsey
GN
Guinea
GS
South Georgia & South Sandwich Islands
GW
Guinea-Bissau
HT
Haiti
HN
Honduras
HN-
Honduras
HU
Hungary
IS
Iceland
IN
India
ID
Indonesia
IE
Ireland
IR
Iran
IQ
Iraq
IM
Isle of Man
IL
Israel
IT
Italy
JM
Jamaica
JP
Japan
JE
Jersey
JO
Jordan
KZ
Kazakhstan
KE
Kenya
KR
South Korea
KN
St. Kitts & Nevis
XK
Kosovo
KW
Kuwait
KG
Kyrgyzstan
LA
Laos
LV
Latvia
LB
Lebanon
LS
Lesotho
LR
Liberia
LI
Liechtenstein
LT
Lithuania
LU
Luxembourg
MK
North Macedonia
MG
Madagascar
MY
Malaysia
MV
Maldives
MT
Malta
MH
Marshall Islands
MH+4
Marshall Islands
MU
Mauritius
MQ
Martinique
MW
Malawi
YT
Mayotte
MX
Mexico
FM
Micronesia
FM+4
Micronesia
MD
Moldova
MC
Monaco
MN
Mongolia
ME
Montenegro
MA
Morocco
MZ
Mozambique
MM
Myanmar (Burma)
NA
Namibia
NP
Nepal
NC
New Caledonia
NZ
New Zealand
NI
Nicaragua
NE
Niger
NG
Nigeria
NF
Norfolk Island
MP
Northern Mariana Islands
NO
Norway
OM
Oman
PK
Pakistan
PW
Palau
PW+4
Palau
PS
Palestinian Territories
PA
Panama
PG
Papua New Guinea
PY
Paraguay
PE
Peru
PE+
Peru
PH
Philippines
PL
Poland
PT
Portugal
PT+3
Portugal
PR
Puerto Rico
PR+4
Puerto Rico
RE
Réunion
PM
St. Pierre & Miquelon
PN
Pitcairn Islands
RO
Romania
RU
Russia
LC
St. Lucia
VC
St. Vincent & Grenadines
WS
Samoa
SM
San Marino
SA
Saudi Arabia
SA+4
Saudi Arabia
SN
Senegal
RS
Serbia
SG
Singapore
SH
St. Helena
SK
Slovakia
SI
Slovenia
SO
Somalia
ZA
South Africa
ES
Spain
LK
Sri Lanka
SD
Sudan
SZ
Eswatini
SE
Sweden
CH
Switzerland
SJ
Svalbard & Jan Mayen
TW
Taiwan
TW+2
Taiwan
TJ
Tajikistan
TZ
Tanzania
TH
Thailand
TT
Trinidad & Tobago
TN
Tunisia
TR
Türkiye
TM
Turkmenistan
UA
Ukraine
UY
Uruguay
VI
U.S. Virgin Islands
VI+4
U.S. Virgin Islands
UZ
Uzbekistan
VE
Venezuela
VE-
Venezuela
VN
Vietnam
YU
Serbia
WF
Wallis & Futuna
ZM
Zambia
US
United States
US+4
United States

Example:

<q2-input type="postal" format-modifier="SI"></q2-input>

Design

Input Type

The type attribute of an input element directly affects both its behavior and user expectations. For example, setting the input type to "credit-card" (or a custom implementation using "text" with formatting logic) allows the input to visually match standard credit card number formatting and may include an associated icon to reinforce the context.

Use the correct input type to ensure optimal usability, accessibility, and user trust. For example:

  • type="email" triggers native validation and displays email-specific keyboards on mobile devices.
  • type="number" brings up a numeric keypad but may not be appropriate for inputs like credit card numbers due to formatting constraints.

Choosing the appropriate input type enhances both semantic meaning and interaction affordance.

Placeholders

We discourage relying on placeholder text as a primary method for conveying information. Placeholders disappear on focus, making them an unreliable mechanism for users to reference during data entry—particularly for users with visual or cognitive impairments.

However, when used appropriately, placeholder text can provide brief and contextually helpful hints—such as an example of the expected input format (e.g., MM/YY for expiration dates). Placeholder text should supplement, not replace, form labels or help text. It must not be the only source of essential guidance.

Text Masking

Sensitive inputs, such as passwords, credit card numbers, or social security numbers, should be masked by default to protect user privacy. When text is hidden, always provide a visibility toggle to allow users to reveal and verify their input when needed. This helps prevent errors and improves usability without compromising security.

Input Slots and Icon Placement

When integrating input slots using q2-input components with q2-icon, follow consistent conventions to ensure clarity and usability:

  • Decorative icons should be placed on the left side of the input field. These provide visual context but do not perform actions.
  • Signifiers—icons that represent functional actions (e.g., clear input, reveal password)—should be placed on the right side of the field.

Signifiers communicate specific actions or states. They should be clearly recognizable and aligned with established mental models or help establish new ones. Icons must accurately reflect their associated behavior to prevent confusion.

Patterns

Provide clean examples of how to compose multiple components together in order to achieve a specific visual outcome that is curated and maintained by Tecton.

Full-page patterns

  • Account Details Page

    How to build an Account Details page in Tecton: a sortable, filterable transaction list with client-side search, column sorting, and pagination.

  • Account List Page

    How to build an Account List page in Tecton: a summary header and a searchable, client-filtered account list.

  • Account Settings Page

    How to build an Account Settings page in Tecton: six independent settings sections covering nickname, notifications, statement delivery, card management, spending limits, and overdraft protection.

  • Funds Transfer Page

    How to build a Funds Transfer form in Tecton: a single-column transfer with rich account options, a recurrence schedule, and client-side validation.

  • Profile Page

    How to build a Profile page in Tecton: required-field validation for personal information, real-time cross-field password validation, and plain integration toggles.

Accessibility

Accessibility Report

Tecton components are designed and tested to be WCAG compliant when used appropriately, and do not get released without proper validation. Developers should prefer not to set ARIA attributes when using components from the Tecton Design System.

CSS Variables

The following CSS variables are available to override the default theme styles of the q2-input component.

Dependencies

Many Tecton components consume other components to maintain visual and functional consistency. If you are looking for a CSS variable you think should exist but are not seeing it, it may be defined in one of the dependent components below. Either way, if you think it's something we should expose more conveniently, let us know!

Dependencies

This component uses other components in the Tecton library, including:

  • q2-icon
  • q2-btn
  • q2-badge

Dependents

Other components in the Tecton library use this component, including:

  • q2-calendar
  • q2-editable-field
  • q2-pagination
  • q2-search
  • q2-select

Changelog

The changelog provides a detailed history of new features, improvements, and bug fixes going back to Tecton 1.30.0. If the button is disabled, it indicates there have been no detectable changes since then.

Show changelog (88)