Text Field
An input field used to capture user text input, with an optional label, helper text, and validation state.
Overview
Text fields allow users to enter and edit text within forms, dialogs, and other interfaces. They provide a structured way to collect user input with clear labeling, validation, and formatting support to ensure data quality and usability.
Usage
forge-text-field wraps a child <input> or <textarea> and an optional <label>, handling layout and state through variant, theme, shape, density, label-position, invalid, required, optional, and disabled. For a fixed set of choices, reach for a select or autocomplete instead; for freeform, removable entries like tags or recipients, use a chip field.
Rules
Variant
Set variant to outlined (the default), plain, tonal, filled, or raised to match the field to its surrounding context.
All five field variants.
<forge-text-field variant="plain">
<label slot="label">
Plain
</label>
<input type="text" />
</forge-text-field>
<forge-text-field variant="outlined">
<label slot="label">
Outlined
</label>
<input type="text" />
</forge-text-field>
<forge-text-field variant="tonal">
<label slot="label">
Tonal
</label>
<input type="text" />
</forge-text-field>
<forge-text-field variant="filled">
<label slot="label">
Filled
</label>
<input type="text" />
</forge-text-field>
<forge-text-field variant="raised">
<label slot="label">
Raised
</label>
<input type="text" />
</forge-text-field>Label position
Set label-position to control where the label sits relative to the input: inset (the default) floats it inside the field, block-start places it above, inline-start and inline-end place it beside the field, and none hides it. Only use none for a search or filter field, and give the <input> an aria-label so it still has an accessible name.
Label positioned above the field.
<forge-text-field label-position="block-start" class="max-w-[500px]">
<label slot="label" for="forge-input-7i1qj">
Label
</label>
<input type="text" id="forge-input-7i1qj">
</forge-text-field>Label positioned inline, beside the field.
<forge-text-field label-position="inline-start" class="max-w-[500px]">
<label slot="label" for="forge-input-n5xb7">
Label
</label>
<input type="text" id="forge-input-n5xb7">
</forge-text-field>Helper text and validation
Slot support text in the helper-text slot, set required for a required field, and set invalid to swap in error text describing the fix.
Helper text, a required field, and an invalid field with error text.
<forge-text-field>
<label slot="label">
Email
</label>
<input type="email" />
<span slot="support-text">
We'll only use this to send a receipt.
</span>
</forge-text-field>
<forge-text-field required>
<label slot="label">
Full name
</label>
<input type="text" />
</forge-text-field>
<forge-text-field invalid>
<label slot="label">
Email
</label>
<input type="email" value="not-an-email" />
<span slot="support-text">
Enter a valid email, like name@example.com.
</span>
</forge-text-field>Multiline
Slot a <textarea> instead of an <input> for longer, multi-line responses. Prefer it over letting a single-line input grow, and size it to fit within mobile screen heights.
A textarea slotted in place of an input.
<forge-text-field class="max-w-[500px]">
<label slot="label" for="forge-input-wqhug">
Label
</label>
<textarea id="forge-input-wqhug">
</textarea>
</forge-text-field>Clear button
Set show-clear to add a button that clears the field’s value, appearing once the field has a value.
A clear button appears once the field has a value.
<forge-text-field show-clear>
<label slot="label">
Search
</label>
<input type="text" value="Prefilled value" />
</forge-text-field>Leading and trailing content
Slot an icon or short text in the start slot to render it before the input, or in the end slot to render it after, like a unit suffix.
Search and filter fields
A search or filter field is the one place a field may go without a visible label. Set label-position="none", put a search icon in the start slot, set show-clear, and use a short placeholder like “Search” or “Filter by name” in place of the label. Give the <input> an aria-label, since the placeholder isn’t an accessible name.
<forge-text-field label-position="none" show-clear>
<forge-icon slot="start" name="search"></forge-icon>
<input type="search" placeholder="Search" aria-label="Search" />
</forge-text-field>
Every other form field keeps a visible label and doesn’t use a placeholder.
Disabled and readonly
Set disabled to exclude the field from the form.
A disabled field.
<forge-text-field disabled>
<label slot="label">
Disabled
</label>
<input type="text" value="Can't edit this" />
</forge-text-field>The Forge Text Field component is an input field used to capture user text input. It requires a child `<input>` or `<textarea>` element to function properly, and an optional `<label>` element can be used to provide a label for the `<input>`.
import "@tylertech/forge/text-field";| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
popoverTargetElement | — | HTMLElement | — | Gets a reference to the element that the popover should target for best alignment. |
showClear | show-clear | boolean | false | Whether the clear button appears when text has been entered. |
labelPosition | label-position | FieldLabelPosition | "inset" | The position of the label relative to the field. |
labelAlignment | label-alignment | FieldLabelAlignment | "start" | The alignment of the label relative to the field. |
invalid | invalid | boolean | false | Whether the field is in an invalid state. |
required | required | boolean | false | Whether the field is required. |
optional | optional | boolean | false | Whether the field is optional. |
disabled | disabled | boolean | false | Whether the field is disabled. |
floatLabel | float-label | boolean | false | Whether the label should float above the field. Only applies when the label is inset. |
variant | variant | FieldVariant | "outlined" | The variant of the field. |
theme | theme | FieldTheme | "default" | The theme of the field. |
shape | shape | FieldShape | "default" | The shape of the field. |
density | density | FieldDensity | "default" | The density of the field. |
dense | dense | boolean | false | Whether the field is dense. |
popoverIcon | popover-icon | boolean | false | Whether the field has a popover icon. |
popoverExpanded | popover-expanded | boolean | false | Whether the field's popover is expanded. |
supportTextInset | support-text-inset | FieldSupportTextInset | "none" | The inset of the support text. |
| Name | Type | Description |
|---|---|---|
forge-text-field-clear | CustomEvent<void> | Dispatched when the clear button is clicked. |
forge-field-popover-icon-click | CustomEvent<void> | Dispatches when the user clicks the popover icon. |
| Name | Description |
|---|---|
(default) | The default/unnamed slot for the field's input. |
label | Renders its content as a positioned label. |
start | Typically reserved for content/icons that render logically before the default slot content. |
end | Typically reserved content/icons that render logically after the default slot content. |
clear-button | Content slotted here replaces the default clear button. |
clear-button-tooltip | Sets the text content of the clear button's tooltip and accessible label. |
accessory | Used for content such as a button that is logically connected to the field but should appear distinct from the input. |
support-text | Used for content that provides additional information about the field. Aligns to the inline start of the field. |
support-text-end | Used for content that provides additional information about the field. Aligns to the inline end of the field. |
| Name | Description |
|---|---|
::part(root) | The root container element. |
::part(label) | The label element. |
::part(container) | The container element surrounding the input. |
::part(input) | The element containing te input slot. |
::part(start) | The element containing the start slot. |
::part(end) | The element containing the end slot. |
::part(popover-icon) | The popover icon element. |
::part(accessory) | The element containing the accessory slot. |
::part(support-text) | The support text element. |
::part(support-text) | The support text element. |
::part(support-text-end) | The element containing the support text end slot. |
::part(outline) | The element containing the forge-focus-indicator element. |
::part(focus-indicator) | The focus indicator element. |
| Name | Description |
|---|---|
--forge-field-background | The background of the field surface. |
--forge-field-tonal-background | The background of the field surface in the tonal variant. |
--forge-field-tonal-background-hover | The background of the field surface in the tonal variant on hover. |
--forge-field-filled-background | The background of the field surface in the filled and raised variants. |
--forge-field-outline-style | The style of the field outline. |
--forge-field-outline-width | The width of the field outline. |
--forge-field-shape | The border radius of the field's corners. |
--forge-field-height | The height of the field in its default density. |
--forge-field-inset-height | The height of the field in its default density when the label is inset. |
--forge-field-padding-inline | The inline padding of the field. |
--forge-field-padding-inline-start | The inline start padding of the field. |
--forge-field-padding-inline-end | The inline end padding of the field. |
--forge-field-inner-padding-inline | The padding between elements slotted into the field. |
--forge-field-support-text-margin-block | The margin between the support text and the field. |
--forge-field-support-text-gap | The minimum gap between the support text and the support text end. |
--forge-field-support-text-padding-inline | The inline padding of the support text. |
--forge-field-support-text-padding-inline-start | The inline start padding of the support text. |
--forge-field-support-text-padding-inline-end | The inline end padding of the support text. |
--forge-field-label-margin-inline | The margin between the label and the field when the label is in an inline position. |
--forge-field-label-margin-block | The margin between the label and the field when the label is in the block start position. |
--forge-field-required-padding | The padding between the required indicator and the label. |
--forge-field-required-content | The content of the required indicator. |
--forge-field-optional-padding | The padding between the optional indicator and the label. |
--forge-field-optional-content | The content of the optional indicator. |
--forge-field-multiline-resize | The direction the field can be resized when multiline. |
--forge-field-multiline-min-inline-size | The minimum inline size the field can be resized to when multiline. |
--forge-field-multiline-max-inline-size | The maximum inline size the field can be resized to when multiline. |
--forge-field-multiline-min-block-size | The minimum block size the field can be resized to when multiline. |
--forge-field-multiline-max-block-size | The maximum block size the field can be resized to when multiline. |
--forge-field-popover-icon-transition-duration | The duration of the popover icon animation. |
--forge-field-popover-icon-transition-timing | The timing function of the popover icon animation. |
--forge-field-popover-icon-open-rotation | The rotation of the popover icon when open. |
--forge-field-surface-animation-duration | The duration of background and outline animations. |
--forge-field-surface-animation-timing | The timing function of background and outline animations. |
--forge-field-surface-floating-animation-duration | The duration of the floating label animation. |
--forge-field-surface-floating-animation-timing | The timing function of the floating label animation. |
--forge-field-focus-indicator-width | The width of the focus indicator. |
--forge-field-disabled-opacity | The opacity of the field when disabled. |
--forge-field-disabled-background | The background of the field when disabled. |
| Name | Returns | Description |
|---|---|---|
floatLabelWithoutAnimation(value) | void | Floats the label immediately. Only applies when the label is inset. |
Labeling
If you’re not using a <label> element, provide an aria-label or aria-labelledby attribute on the <input> directly.