Text Field
Single-line input with icon slots, clear button, helper and error text, and a character counter.
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. |
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 the element and state they target. 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 | 3px solid rgba(71, 110, 249, 0.2) | |
--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 | 3px solid rgba(220, 38, 38, 0.2) | |
--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__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 | |
c2-text-field-clear
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. |
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 the element and state they target. 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 | 3px solid rgba(71, 110, 249, 0.2) | |
--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 | 3px solid rgba(220, 38, 38, 0.2) | |
--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__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 | |