Back to Fluentui

The `TextInput` Custom Element

packages/web-components/src/text-input/README.md

4.40.2-hotfix211.3 KB
Original Source

The TextInput Custom Element

A partial implementation of an <input> as a form-associated custom element.

The <fluent-text-input> is intended to match feature parity with the Fluent UI React 9 <Input /> component. However, due to the nature of web components there will not be 100% parity between the two.

View the Text Input Design Spec in Figma

API

Class: TextInput

Definition

DetailDescription
Tag Name<fluent-text-input>
SuperclassFASTElement

Static Fields

NamePrivacyTypeDefaultDescriptionInherited From
formAssociatedpublicbooleantrueThe form-associated flag.

Fields

NamePrivacyTypeDefaultDescription
appearancepublicTextInputAppearance'outline'Indicates the styled appearance of the element.
autocompletepublicstring | undefinedIndicates the element's autocomplete state.
autofocuspublicbooleanIndicates that the element should get focus after the page finishes loading.
controlSizepublicTextInputControlSize | undefined'medium'Sets the size of the control.
dirnamepublicstring | undefinedSets the directionality of the element to be submitted with form data.
disabledpublicboolean | undefinedSets the element's disabled state.
formAttributepublicstring | undefinedThe id of a form to associate the element to.
initialValuepublicstringThe initial value of the input.
listpublicstringAllows associating a REPLACELTdatalistREPLACEGT to the element by ID.
maxlengthpublicnumberThe maximum number of characters a user can enter.
minlengthpublicnumberThe minimum number of characters a user can enter.
multiplepublicbooleanIndicates that a comma-separated list of email addresses can be entered. This attribute is only valid when type="email".
namepublicstringThe name of the element. This element's value will be surfaced during form submission under the provided name.
patternpublicstringA regular expression that the value must match to pass validation.
placeholderpublicstringSets the placeholder value of the element, generally used to provide a hint to the user.
readonlypublicboolean | undefinedWhen true, the control will be immutable by user interaction.
requiredpublicbooleanThe element's required attribute.
sizepublicnumberSets the width of the element to a specified number of characters.
spellcheckpublicbooleanControls whether or not to enable spell checking for the input field, or if the default spell checking configuration should be used.
typepublicTextInputTypeAllows setting a type or mode of text.
validitypublicValidityStateThe element's validity state.
validationMessagepublicstringThe validation message.
valuepublicstringThe current value of the input.
willValidatepublicbooleanDetermines if the control can be submitted for constraint validation.
formpublicHTMLFormElement | nullThe associated form element.
rolestring'textbox'

Methods

NamePrivacyDescriptionParametersReturn
selectpublicSelects all the text in the text field.void
setValiditypublicSets the validity of the control.<ul><li>flags: ValidityStateFlags</li><li>message: string</li><li>anchor: HTMLElement</li></ul>void

Attributes

NameField
appearanceappearance
autocompleteautocomplete
autofocusautofocus
control-sizecontrolSize
dirnamedirname
disableddisabled
formformAttribute
valueinitialValue
listlist
maxlengthmaxlength
minlengthminlength
multiplemultiple
namename
patternpattern
placeholderplaceholder
readonlyreadonly
requiredrequired
sizesize
spellcheckspellcheck
typetype

CSS Parts

NameDescription
labelThe internal <label> element
rootthe root container for the internal control
controlThe internal <input> control

Slots

NameDescription
startContent which can be provided before the input
endContent which can be provided after the input
The default slot for button content
<hr/>

Exported Variables

NameDescriptionType
TextInputControlSizeValues for the control-size attribute on TextInput elements."small" | "medium" | "large"
TextInputAppearanceValues for the appearance attribute on TextInput elements."outline" | "underline" | "filled-lighter" | "filled-darker"
TextInputTypeValues for the type attribute on TextInput elements."email" | "password" | "tel" | "text" | "url"
ImplicitSubmissionBlockingTypesInput types that block implicit form submission.array
<hr/>

Accessibility

WAI-ARIA Roles, States, and Properties

This component supports ARIA attributes that inherit from the ARIA Global States and Properties.

<hr />

Fluent Web Component v3 v.s Fluent React 9

Component and Slot Mapping

Fluent UI React 9Fluent Web Components 3
<Input><fluent-text-input>
contentBeforestart
contentAfterend

Block and Inline Display

The Fluent UI <Input /> component design spec offers two appearance variations for the display property - block (default) and inline. To achieve the inline variation, users should apply their own custom CSS.

css
fluent-text-input {
  display: inline-flex;
  align-items: center;
}