Skip to content

Text field - Elements ​

A text field is a single-line input component used for entering and editing textual data.

AndroidreleasedElementsreleasediOSreleasedReactreleasedVuereleased

Accessibility ​

If a visible label isn't specified, an aria-label must be provided to the text field for accessibility. If the field is labeled by a separate element, an aria-labelledby property must be provided using the id of the labeling element instead.

  • Always provide a visible label (do not rely on placeholder alone).
  • Do not rely on color alone for interaction feedback (e.g. error states).
  • Interaction patterns should follow platform-native expectations (e.g. tap zones, keyboard navigation, etc) and must not block accessibility tools.

When used with an affix ​

When search or clear set on the affix component it renders a button and a default aria-label. If the aria-label incorrect for your context, you may provide your own describing the action.

html
<w-affix search aria-label="Ad Search"></w-affix>
<w-affix clear aria-label="Clear text input"></w-affix>

Usage ​

html
<w-textfield label="Email" type="email"></w-textfield>

Validation ​

Set the invalid attribute to display a textfield as invalid.

invalid should be paired with help-text to provide feedback to the user about how to correct the error.

html
<w-textfield 
    label="Email"
    invalid
    help-text="An email should have an @ sign and a domain name, for example ola.nordmann@finn.no"
></w-textfield>

Examples ​

Placeholder ​

Placeholder text can be used to describe the expected value or formatting for the textfield.

Placeholder text will only appear when the textfield is empty, and must not be used as a substitute for labeling the element with a visible label.

html
<w-textfield label="Email" placeholder="ola.nordmann@finn.no"></w-textfield>

Prefix label ​

html
<w-textfield label="Price">
  <w-affix slot="prefix" label="kr"></w-affix>
</w-textfield>

Suffix Label ​

html
<w-textfield label="Price">
  <w-affix slot="suffix" label="kr"></w-affix>
</w-textfield>

Prefix Search Icon ​

html
<w-textfield label="Search">
  <w-affix slot="prefix" search></w-affix>
</w-textfield>

Suffix Search Icon ​

If you wrap the textfield with affix in a form element, clicking the search button will automatically submit the form

html
<form>
  <w-textfield label="Search">
    <w-affix slot="prefix" search></w-affix>
  </w-textfield>
</form>

Suffix Clear Icon ​

Clicking the clear button will reset the textfield

html
<w-textfield label="Search input">
  <w-affix slot="suffix" clear></w-affix>
</w-textfield>

Affix with arbitrary icon ​

html
<w-textfield label="Award">
  <w-affix slot="prefix" icon="AwardMedal"></w-affix>
</w-textfield>

Disabled ​

Keep in mind that using disabled in its current form is an anti-pattern.

There will always be users who don't understand why an element is disabled, or users who can't even see that it is disabled because of poor lighting conditions or other reasons.

Please consider more informative alternatives before choosing to use disabled on an element.

html
<div class="flex flex-col space-y-32">
  <w-textfield label="Email" disabled value="ola.nordmann@finn.no"></w-textfield>
  <w-textfield label="Email" disabled></w-textfield>
</div>

Read only ​

The readonly boolean attribute makes the w-textfield's text content immutable. Unlike disabled the w-textfield remains focusable and the contents can still be copied. See MDN docs for more information.

html
<w-textfield 
  label="Email" 
  type="email" 
  value="ola.nordmann@finn.no" 
  readonly
></w-textfield>

Styling API ​

This section documents the supported styling hooks for <w-textfield>.

Use these hooks to customize appearance without relying on internal structure or selectors.

Before changing the default styles, remember that doing so can result in less consistent experiences for users across the product. Prefer defaults.

  • Prefer component tokens for size, spacing, and state styling.
  • Use parts only for small, local tweaks.
  • Avoid relying on internal class names or selectors.

Parts ​

The textfield exposes a minimal set of parts that can be targeted for last‑mile layout or typography tweaks.

PartTargetsTypical use
inputnative input elementminor typography or spacing tweaks

Example:

css
w-textfield::part(input) {
  letter-spacing: 0.5px;
}

Parts are intended as an escape hatch. Prefer component tokens for anything state‑ or size‑related.

Component tokens ​

Component tokens (--w-c-input-*) act as inputs to the textfield styling. They can be set directly on the component or inherited from a parent container.

These tokens are shared across textfield, textarea, and select for consistent form styling.

css
.form-section {
  --w-c-input-label-font-weight: 600;
  --w-c-input-help-text-color: var(--w-s-color-text);
}

Defaults are defined internally; setting a token is always optional.

Label tokens ​

TokenPurposeDefault
--w-c-input-label-colorlabel text color--w-s-color-text
--w-c-input-label-font-sizelabel font size--w-font-size-s
--w-c-input-label-line-heightlabel line height--w-line-height-s
--w-c-input-label-font-weightlabel font weight700
--w-c-input-label-padding-bottomspace below label0.4rem
--w-c-input-label-cursorcursor when hovering labelpointer
--w-c-input-label-displaylabel display modeblock

Optional indicator tokens ​

When optional attribute is set, these tokens control the "(optional)" text styling:

TokenPurposeDefault
--w-c-input-optional-coloroptional text color--w-s-color-text-subtle
--w-c-input-optional-font-sizeoptional text font size--w-font-size-s
--w-c-input-optional-line-heightoptional text line height--w-line-height-s
--w-c-input-optional-font-weightoptional text font weight400
--w-c-input-optional-padding-leftspace before optional text0.8rem

Help text tokens ​

TokenPurposeDefault
--w-c-input-help-text-colorhelp text color (normal state)--w-s-color-text-subtle
--w-c-input-help-text-color-invalidhelp text color when invalid--w-s-color-text-negative
--w-c-input-help-text-font-sizehelp text font size--w-font-size-xs
--w-c-input-help-text-line-heighthelp text line height--w-line-height-xs
--w-c-input-help-text-margin-topspace above help text0.4rem
--w-c-input-help-text-displayhelp text display modeblock

Implementation notes ​

Shared token system ​

Textfield shares its label, optional indicator, and help text tokens with w-textarea and w-select. This ensures consistent form styling across all text input components.

Affix accessibility ​

Due to shadow DOM boundaries, affix content (prefix/suffix slots) cannot be connected to the input via ARIA references. For non-interactive affixes like currency symbols or unit labels, consider including that information in the main label or placeholder text instead for better screen reader support.

<w-textfield> API ​

Unless otherwise noted all properties are HTML attributes (as opposed to JavaScript object properties).

Properties ​

NameTypeDefaultSummary
autocompleteHTMLInputElement["autocomplete"] | undefined-A space-separated string that hints to browsers what type of content it can suggest to autofill.
disabledbooleanfalseMakes the element not focusable and hides it from form submits
formatter (JS only)((value: string) => string) | undefined-Function to format value when the input field
handler (JS only)handler(e: Event) => void--
help-textstring | undefined-Description shown below the input field
invalidbooleanfalseMark the form field as invalid.
labelstring | undefined-Either a label or an aria-label must be provided.
maxnumber | undefined-Use with type="number" to set the maximum allowed value.
max-lengthnumber | undefined-Deprecated: Use the native maxlength attribute
maxlengthnumber | undefined-For text, search, url, tel, email and password fields, sets the maximum string length allowed.
minnumber | undefined-Use with type="number" to set the minimum allowed value.
min-lengthnumber | undefined-Deprecated: Use the native minlength attribute
minlengthnumber | undefined-For text, search, url, tel, email and password fields, sets the minimum string length required.
namestring | undefined-The name of the input field when submitting the form.
optionalbooleanfalseWhether to show the optional indicator after the label.
patternstring | undefined-Sets a regular expression that the input's value must match to pass validation
placeholderstring | undefined-Shown in the textfield when it doesn't have a value
prefixSlotChange (JS only)prefixSlotChange() => void--
read-onlybooleanfalseDeprecated: Use the native readonly attribute instead.
readonlybooleanfalseWhether the input can be selected but not changed by the user.
requiredbooleanfalseWhether user input is required on the input before form submission.
resetFormControl (JS only)resetFormControl() => void--
sizestring | undefined-Sets the size (width) of the input field to fit the expected length of inputs.
stepnumber | undefined-Forces number inputs to be a whole number of step
suffixSlotChange (JS only)suffixSlotChange() => void--
typestring | undefined-The type of input.
valuestring | undefined-Lets you set the current value.

Property Details ​

autocomplete ​

A space-separated string that hints to browsers what type of content it can suggest to autofill.

  • Type: HTMLInputElement["autocomplete"] | undefined
  • Default: -

disabled ​

Keep in mind that using disabled in its current form is an anti-pattern.

There will always be users who don't understand why an element is disabled, or users who can't even see that it is disabled because of poor lighting conditions or other reasons.

Please consider more informative alternatives before choosing to use disabled on an element.

  • Type: boolean
  • Default: false

formatter (JS only) ​

Function to format value when the input field.

Only active when the input field does not have focus, similar to the accessible input masking example from Filament Group.

  • Type: ((value: string) => string) | undefined
  • Default: -

handler (JS only) ​

  • Type: handler(e: Event) => void
  • Default: -

help-text ​

Use in combination with invalid to show as a validation error message, or on its own to show a help text.

  • Type: string | undefined
  • Default: -

invalid ​

Mark the form field as invalid. Make sure to also set a help-text to help users fix the validation problem.

  • Type: boolean
  • Default: false

label ​

Either a label or an aria-label must be provided.

  • Type: string | undefined
  • Default: -

max ​

Use with type="number" to set the maximum allowed value.

  • Type: number | undefined
  • Default: -

max-length ​

Deprecated: Use the native maxlength attribute

  • Type: number | undefined
  • Default: -

maxlength ​

For text, search, url, tel, email and password fields, sets the maximum string length allowed.

  • Type: number | undefined
  • Default: -

min ​

Use with type="number" to set the minimum allowed value.

  • Type: number | undefined
  • Default: -

min-length ​

Deprecated: Use the native minlength attribute

  • Type: number | undefined
  • Default: -

minlength ​

For text, search, url, tel, email and password fields, sets the minimum string length required.

  • Type: number | undefined
  • Default: -

name ​

The name of the input field when submitting the form.

  • Type: string | undefined
  • Default: -

optional ​

Whether to show the optional indicator after the label.

  • Type: boolean
  • Default: false

pattern ​

Sets a regular expression that the input's value must match to pass validation

  • Type: string | undefined
  • Default: -

placeholder ​

Set a text that is shown in the textfield when it doesn't have a value.

Placeholder text should not be used as a substitute for labeling the element with a visible label.

  • Type: string | undefined
  • Default: -

prefixSlotChange (JS only) ​

  • Type: prefixSlotChange() => void
  • Default: -

read-only ​

Deprecated: Use the native readonly attribute instead.

  • Type: boolean
  • Default: false

readonly ​

Whether the input can be selected but not changed by the user.

  • Type: boolean
  • Default: false

required ​

Whether user input is required on the input before form submission.

  • Type: boolean
  • Default: false

resetFormControl (JS only) ​

  • Type: resetFormControl() => void
  • Default: -

size ​

Sets the size (width) of the input field to fit the expected length of inputs.

  • Type: string | undefined
  • Default: -

step ​

When used with number this attribute forces inputs to be a whole number of step.

For example with a step="5" only values that divide evenly on 5 are allowed. Using arrow up and down in the input field increments and decrements by 5.

  • Type: number | undefined
  • Default: -

suffixSlotChange (JS only) ​

  • Type: suffixSlotChange() => void
  • Default: -

type ​

The type of input.

  • Type: string | undefined
  • Default: -

value ​

Lets you set the current value.

  • Type: string | undefined
  • Default: -

Questions? ​

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system