Create

Form

Input

Copy page View as Markdown Open in ChatGPT Open in Claude

Displays a form input field or a component that looks like an input field.

Usage#

app.component.ts
import { WdsInputComponent } from '@wds/angular/input';

Examples#

Default#

Without wds-field give the input a name with aria-label.

Field#

In wds-field the label and the description become the accessible name and description of the input.

Username Choose a unique username for your account.

Form#

wds-input is a form-associated element: it is submitted under name, validated by the browser (required, type="email", pattern...) and restored by a form reset. Enter submits the form.

NameEmailWe'll send a confirmation to this address.
ResetSubmit

Submitted: —

Disabled#

Email This field is currently disabled.

Invalid#

invalid on wds-field or on the input shows the error state.

Invalid input This field contains validation errors.

File#

Picture Select a picture to upload.

Inline#

Search

Grid#

First name Last name

Required#

The asterisk is decorative (aria-hidden); required tells screen readers that the field is required.

Required field This field must be filled out.

Badge#

Webhook URL Beta

Input group#

Website URL https://

Button group#

Search Search

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsTextField connects the input to [formField]. Validators from the schema (required, email, minLength...) show their messages through wds-field-error.

NameEmailSubmit

Submitted: —

Template-driven#

WdsTextValueAccessor makes ngModel work on wds-input. Angular validators (required, email, minlength...) work as on a native input.

NameEmailSubmit

Submitted: —

Reactive forms#

The same WdsTextValueAccessor works with formControl and formControlName.

NameEmailSubmit

Submitted: —

API References#

wds-input#

A text field. A native <input> inside; it works in a <form> and with wds-field. Enter submits the form like a native <input> (the default submit button).

Attributes

AttributeTypeDefaultDescription
typestring'text'Native type: text, email, password, search, url, tel, number, file...
patternstring | undefinedRegular expression the value must match (native validation).
minstring | undefinedMinimum value (number, dates).
maxstring | undefinedMaximum value (number, dates).
stepstring | undefinedStep between allowed values (number, dates).
inputmodestring | undefinedVirtual keyboard hint, e.g. numeric, email.
valuestring''Current value.
namestring''Field name in the form. Reflected to the attribute, which FormData uses (also when a framework sets it as a property).
placeholderstring''Text shown while the field is empty.
disabledbooleanfalseDisables the field and excludes it from form submission.
readonlybooleanfalseThe value can be read and selected, but not changed.
requiredbooleanfalseA value is required for the form to be valid.
invalidbooleanfalseError state: red border and aria-invalid.
autocompletestring''Native autocomplete hint.
minlength.minLengthnumber | undefinedMinimum length of the value (native validation).
maxlength.maxLengthnumber | undefinedMaximum length of the value.

Events

EventDescription
wds-inputCustomEvent<WdsTextChangeDetail>Every change of the value.
wds-changeCustomEvent<WdsTextChangeDetail>A committed change (blur, Enter).

Methods

MethodDescription
select()Selects all text.
formResetCallback()
formDisabledCallback(disabled: boolean)
formStateRestoreCallback(state: string | File | FormData | null)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

CSS parts (::part)

PartDescription
controlThe native <input>.

Accessibility#

Screen reader#

wds-input renders a native <input> of the given type, so it is announced as an edit field (or a file button for type="file"). Without wds-field give it a name with aria-label on the element: it is forwarded to the native input.

In wds-field, wds-field-label names the input and wds-field-description and wds-field-error describe it. invalid sets aria-invalid="true"; disabled, readonly and required are set on the native input.

The placeholder is not a name: always give the input a label.

Keyboard support#

KeyFunction
TabMoves focus to the input. A disabled input is skipped.
EnterCommits the value (wds-change) and submits the form, as in a native input.
Footer