A standard input field with many options including various masked types, error or hint displays, and much more.
Format Modifiers give you a granular level of control over the behavior of the field, which are different for each input type.
alpha
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.
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.
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>
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>
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:
<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>
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>
The q2-input
element has multiple slots that can be used to insert custom content into the component.
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.
The q2-input
element has one or more properties that support text localization. Those properties are indicated by the localizable badge in the description.
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.
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.
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.
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.
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.
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).
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.
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"
The q2-input
element exposes events that can be used to send and receive data from the component based on user interaction.
Emitted when the field loses focus after the value has been changed.
IEventDetail
If an event handler is bound to the element using:
onchange
property - The default handler will not fire, and the value must be updated in the custom handler.addEventListener("change")
method - The default handler will fire alongside the custom handler.Emitted when the field value is cleared.
Requires the clearable
prop to be set to true
.
undefined
Emitted when the field value is formatted.
IFormatterValueObject
Emitted when the field value is updated.
IEventDetail
If an event handler is bound to the element using:
oninput
property - The default handler will not fire, and the value must be updated in the custom handler.addEventListener("input")
method - The default handler will fire alongside the custom handler.Emitted when the validation is updated.
IEventDetail
If an event handler is bound to the element using:
oninvalid
property - The default handler will not fire, and the value must be updated in the custom handler.addEventListener("invalid")
method - The default handler will fire alongside the custom handler.The q2-input
element exposes methods that can be used to perform various actions on the component.
Emulates firing checkValidity on <input>
, emits invalid
event if validation failed.
checkValidity() => Promise<boolean>
Emulates clicking the clear button when the input is clearable.
clearValue() => Promise<void>
Only applicable when the input is clearable.
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.
setValue(value: string) => Promise<void>
This component uses other components in the Tecton library, including:
q2-icon
q2-btn
q2-badge
Other components in the Tecton library use this component, including:
q2-calendar
q2-editable-field
q2-pagination
q2-select
Initial Release
Add slots for input-left
and input-right
Added the following {{format-modifier}} options for {{numeric}} types:
Ndecimal-delimited-positive
Ndecimal-positive
Ndecimal-delimited
integer-delimited-positive
integer-positive
integer-delimited
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:
Choosing the appropriate input type enhances both semantic meaning and interaction affordance.
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.
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.
When integrating input slots using q2-input components with q2-icon, follow consistent conventions to ensure clarity and usability:
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.
The following CSS variables are available to override the default theme styles of the q2-input
component.
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!
There are 3 frequently asked questions related to this page.