Text Field
Single-line input with icon slots, clear button, helper and error text, and a character counter.
c2-text-field
A single-line input wrapped in a themeable field. The native <input> keeps its behaviour (type, name,
autocomplete, maxlength, pattern, input/change events); the field adds prefix-icon / suffix-icon slots
sized by --c2-text-field__icon--size, an optional clear button (clearable), helper text (help), an error
message (error + error-text), a character counter when maxlength is set, and a help-icon slot beside the
field. Pair it with c2-label for a caption. Give the host a width: the field fills it.
The host exposes its state as custom states, never as classes: c2-text-field:state(focus-within),
:state(error), :state(read-only) and :state(disabled) (also set while a disabled fieldset disables it).
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
readonly | boolean | false | Shows the value but refuses edits. Rendered on a light grey background. |
disabled | boolean | false | Disables the input and dims the field. |
error | boolean | false | Marks the field invalid: red border and, when set, error-text replaces the helper text. |
maxlength | number | -1 | Maximum number of characters. Forwarded to the input and shown as a n / max counter under the field. |
minlength | number | -1 | Minimum number of characters, forwarded to the input. |
pattern | string | — | Regular expression the value must match, forwarded to the input. |
required | boolean | false | Marks the input required (native validation). Pair with a required c2-label to show the indicator. |
type | TextFieldType | text | Input type: text, email, password, search, tel, url or number. |
name | string | — | Form field name forwarded to the input. |
autocomplete | string | — | autocomplete hint forwarded to the input, e.g. email or current-password. |
placeholder | string | — | Text shown while the field is empty. |
aria-label | string | null | null | Accessible name forwarded to the native input. |
value | string | — | The current text. Setting the attribute after the user has typed no longer updates it, like a native input. |
error-text | string | — | Message shown under the field while error is set. |
help | string | — | Helper text shown under the field. |
clearable | boolean | false | Shows a clear button at the end of the field while it has a value. |
Slots
| Name | Description |
|---|---|
prefix-icon | Icon (or short adornment text) at the start of the field: an inline SVG, a c2-feather-* icon or a c2-mat-icon. Icons are sized by --c2-text-field__icon--size; an adornment keeps its own width. |
suffix-icon | Icon or adornment at the end of the field, after the clear button. |
clear-icon | Replaces the default cross of the clear button. |
help-icon | Icon shown beside the field, outside the border, e.g. a tooltip trigger. |
supporting-text | Rich helper content below the field. help and error-text are the plain-text shortcuts. |
Events
| Name | Type | Description |
|---|---|---|
input | InputEvent | Re-dispatched from the inner input on every keystroke; value is already updated. |
change | Event | Re-dispatched from the inner input when the value is committed (blur or Enter). |
clear | Event | Fired after the clear button emptied the field (an input and a change event follow). |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-text-field--min-height | pixel | 36px | |
--c2-text-field--gap | pixel | 8px | Space between the icons and the text. |
--c2-text-field--border-top-left-radius | border-radius | 6px | |
--c2-text-field--border-top-right-radius | border-radius | 6px | |
--c2-text-field--border-bottom-left-radius | border-radius | 6px | |
--c2-text-field--border-bottom-right-radius | border-radius | 6px | |
--c2-text-field--padding-top | padding | 6px | |
--c2-text-field--padding-right | padding | 10px | |
--c2-text-field--padding-bottom | padding | 6px | |
--c2-text-field--padding-left | padding | 12px | |
--c2-text-field--border-top | border | 1px solid #bcbcc6 | |
--c2-text-field--border-right | border | 1px solid #bcbcc6 | |
--c2-text-field--border-bottom | border | 1px solid #bcbcc6 | |
--c2-text-field--border-left | border | 1px solid #bcbcc6 | |
--c2-text-field--color | color | #18181b | |
--c2-text-field--background | color | #ffffff | |
--c2-text-field--font-size | font-size | 14px | |
--c2-text-field--font-weight | font-weight | — | |
--c2-text-field--font-style | font-style | — | |
--c2-text-field--font-family | font-family | — | |
--c2-text-field--line-height | pixel | 20px | |
--c2-text-field__placeholder--color | color | #71717a | |
--c2-text-field__placeholder--opacity | opacity | 1 | |
--c2-text-field__placeholder--font-weight | font-weight | — | |
--c2-text-field__placeholder--font-style | font-style | — | |
--c2-text-field__hover--border-top | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-right | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-bottom | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-left | border | 1px solid #a1a1aa | |
--c2-text-field__focus--border-top | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-right | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-bottom | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-left | border | 1px solid #476ef9 | |
--c2-text-field__focus--color | color | — | |
--c2-text-field__focus--background | color | — | |
--c2-text-field__focus--outline | outline | none | |
--c2-text-field__focus--outline-offset | pixel | 0px | |
--c2-text-field__error--border-top | border | 1px solid #dc2626 | |
--c2-text-field__error--border-right | border | 1px solid #dc2626 | |
--c2-text-field__error--border-bottom | border | 1px solid #dc2626 | |
--c2-text-field__error--border-left | border | 1px solid #dc2626 | |
--c2-text-field__error--color | color | — | |
--c2-text-field__error--background | color | — | |
--c2-text-field__error__focus--outline | outline | none | |
--c2-text-field__read-only--border-top | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-right | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-bottom | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-left | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--color | color | — | |
--c2-text-field__read-only--background | color | #fafafa | |
--c2-text-field__disabled--opacity | opacity | 0.38 | |
--c2-text-field__icon--size | pixel | 16px | |
--c2-text-field__icon--color | color | #71717a | |
--c2-text-field__clear-icon--size | pixel | 16px | |
--c2-text-field__clear-icon--color | color | #a1a1aa | |
--c2-text-field__clear-icon__hover--color | color | #18181b | |
--c2-text-field__clear-icon__focus--outline | outline | 2px solid rgba(71, 110, 249, 0.4) | |
--c2-text-field__help-icon--size | pixel | 16px | |
--c2-text-field__help-icon--color | color | #71717a | |
--c2-text-field__help-icon--gap | pixel | 8px | Space between the field and the help icon. |
--c2-text-field__supporting-text--gap | pixel | 4px | Space between the field and the helper line. |
--c2-text-field__supporting-text--font-size | font-size | 12px | |
--c2-text-field__supporting-text--line-height | pixel | 16px | |
--c2-text-field__supporting-text--color | color | #71717a | |
--c2-text-field__supporting-text__error--color | color | #dc2626 | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under text-field, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
clear | Clear | — |
c2-text-field-clear
A c2-text-field that always shows a clear button while it has a value. Prefer c2-text-field with the
clearable attribute; this element remains for markup that cannot toggle attributes. Inherits every attribute,
slot, event and CSS variable of c2-text-field.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
readonly | boolean | false | Shows the value but refuses edits. Rendered on a light grey background. |
disabled | boolean | false | Disables the input and dims the field. |
error | boolean | false | Marks the field invalid: red border and, when set, error-text replaces the helper text. |
maxlength | number | -1 | Maximum number of characters. Forwarded to the input and shown as a n / max counter under the field. |
minlength | number | -1 | Minimum number of characters, forwarded to the input. |
pattern | string | — | Regular expression the value must match, forwarded to the input. |
required | boolean | false | Marks the input required (native validation). Pair with a required c2-label to show the indicator. |
type | TextFieldType | text | Input type: text, email, password, search, tel, url or number. |
name | string | — | Form field name forwarded to the input. |
autocomplete | string | — | autocomplete hint forwarded to the input, e.g. email or current-password. |
placeholder | string | — | Text shown while the field is empty. |
aria-label | string | null | null | Accessible name forwarded to the native input. |
value | string | — | The current text. Setting the attribute after the user has typed no longer updates it, like a native input. |
error-text | string | — | Message shown under the field while error is set. |
help | string | — | Helper text shown under the field. |
clearable | boolean | false | Shows a clear button at the end of the field while it has a value. |
Slots
| Name | Description |
|---|---|
clear-icon | Replaces the default cross icon. |
prefix-icon | Icon (or short adornment text) at the start of the field: an inline SVG, a c2-feather-* icon or a c2-mat-icon. Icons are sized by --c2-text-field__icon--size; an adornment keeps its own width. |
suffix-icon | Icon or adornment at the end of the field, after the clear button. |
help-icon | Icon shown beside the field, outside the border, e.g. a tooltip trigger. |
supporting-text | Rich helper content below the field. help and error-text are the plain-text shortcuts. |
Events
| Name | Type | Description |
|---|---|---|
input | InputEvent | Re-dispatched from the inner input on every keystroke; value is already updated. |
change | Event | Re-dispatched from the inner input when the value is committed (blur or Enter). |
clear | Event | Fired after the clear button emptied the field (an input and a change event follow). |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-text-field-clear__clear-icon--size | pixel | 24px | |
--c2-text-field-clear__clear-icon--color | color | rgb(70, 70, 70) | |
--c2-text-field--min-height | pixel | 36px | |
--c2-text-field--gap | pixel | 8px | Space between the icons and the text. |
--c2-text-field--border-top-left-radius | border-radius | 6px | |
--c2-text-field--border-top-right-radius | border-radius | 6px | |
--c2-text-field--border-bottom-left-radius | border-radius | 6px | |
--c2-text-field--border-bottom-right-radius | border-radius | 6px | |
--c2-text-field--padding-top | padding | 6px | |
--c2-text-field--padding-right | padding | 10px | |
--c2-text-field--padding-bottom | padding | 6px | |
--c2-text-field--padding-left | padding | 12px | |
--c2-text-field--border-top | border | 1px solid #bcbcc6 | |
--c2-text-field--border-right | border | 1px solid #bcbcc6 | |
--c2-text-field--border-bottom | border | 1px solid #bcbcc6 | |
--c2-text-field--border-left | border | 1px solid #bcbcc6 | |
--c2-text-field--color | color | #18181b | |
--c2-text-field--background | color | #ffffff | |
--c2-text-field--font-size | font-size | 14px | |
--c2-text-field--font-weight | font-weight | — | |
--c2-text-field--font-style | font-style | — | |
--c2-text-field--font-family | font-family | — | |
--c2-text-field--line-height | pixel | 20px | |
--c2-text-field__placeholder--color | color | #71717a | |
--c2-text-field__placeholder--opacity | opacity | 1 | |
--c2-text-field__placeholder--font-weight | font-weight | — | |
--c2-text-field__placeholder--font-style | font-style | — | |
--c2-text-field__hover--border-top | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-right | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-bottom | border | 1px solid #a1a1aa | |
--c2-text-field__hover--border-left | border | 1px solid #a1a1aa | |
--c2-text-field__focus--border-top | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-right | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-bottom | border | 1px solid #476ef9 | |
--c2-text-field__focus--border-left | border | 1px solid #476ef9 | |
--c2-text-field__focus--color | color | — | |
--c2-text-field__focus--background | color | — | |
--c2-text-field__focus--outline | outline | none | |
--c2-text-field__focus--outline-offset | pixel | 0px | |
--c2-text-field__error--border-top | border | 1px solid #dc2626 | |
--c2-text-field__error--border-right | border | 1px solid #dc2626 | |
--c2-text-field__error--border-bottom | border | 1px solid #dc2626 | |
--c2-text-field__error--border-left | border | 1px solid #dc2626 | |
--c2-text-field__error--color | color | — | |
--c2-text-field__error--background | color | — | |
--c2-text-field__error__focus--outline | outline | none | |
--c2-text-field__read-only--border-top | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-right | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-bottom | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--border-left | border | 1px solid #e4e4e7 | |
--c2-text-field__read-only--color | color | — | |
--c2-text-field__read-only--background | color | #fafafa | |
--c2-text-field__disabled--opacity | opacity | 0.38 | |
--c2-text-field__icon--size | pixel | 16px | |
--c2-text-field__icon--color | color | #71717a | |
--c2-text-field__clear-icon--size | pixel | 16px | |
--c2-text-field__clear-icon--color | color | #a1a1aa | |
--c2-text-field__clear-icon__hover--color | color | #18181b | |
--c2-text-field__clear-icon__focus--outline | outline | 2px solid rgba(71, 110, 249, 0.4) | |
--c2-text-field__help-icon--size | pixel | 16px | |
--c2-text-field__help-icon--color | color | #71717a | |
--c2-text-field__help-icon--gap | pixel | 8px | Space between the field and the help icon. |
--c2-text-field__supporting-text--gap | pixel | 4px | Space between the field and the helper line. |
--c2-text-field__supporting-text--font-size | font-size | 12px | |
--c2-text-field__supporting-text--line-height | pixel | 16px | |
--c2-text-field__supporting-text--color | color | #71717a | |
--c2-text-field__supporting-text__error--color | color | #dc2626 | |