A single-line text field to enter and edit data. It supports prefix and suffix content, helper text, form integration and built-in validation.
- Slots
-
prefix— Renders content before the input. -
suffix— Renders content after the input. -
helper-text— Renders content below the input. -
value-missing— Renders content when the required validation fails. -
type-mismatch— Renders content when the url/email type validation fails. -
pattern-mismatch— Renders content when the pattern validation fails. -
too-long— Renders content when the maxlength validation fails. -
too-short— Renders content when the minlength validation fails. -
range-overflow— Renders content when the max validation fails. -
range-underflow— Renders content when the min validation fails. -
step-mismatch— Renders content when the step validation fails. -
custom-error— Renders content when a custom message is set with `setCustomValidity()`. -
invalid— Renders content when the component is in invalid state (validity.valid = false).
- CSS Parts
-
container— The main wrapper that holds all main input elements. -
input— The native input element. -
label— The native label element. -
prefix— The prefix wrapper. -
suffix— The suffix wrapper. -
helper-text— The helper text wrapper. -
prefixed— Added to the container and the input when an element that is not hidden is in the prefix slot. -
suffixed— Added to the container and the input when an element that is not hidden is in the suffix slot. -
filled— Added to the container and the input when the control has a value. -
labelled— Added to the container in the material theme when the control has a label. -
start— The wrapper of the prefix in the material theme. -
notch— The wrapper of the label in the material theme. -
filler— The outline segment between the notch and the end in the material theme. -
end— The wrapper of the suffix in the material theme.
Properties
Section titled "Properties"autocomplete
Section titled "autocomplete"A hint for the browser on how to autofill the control.
autocomplete: string autofocus
Section titled "autofocus"Whether the control receives focus automatically.
autofocus: boolean inputMode
Section titled "inputMode"A hint to the browser for which virtual keyboard layout to display. See relevant MDN article
inputMode: string maxLength
Section titled "maxLength"The maximum string length of the control.
maxLength: number | undefined minLength
Section titled "minLength"The minimum string length required by the control.
minLength: number | undefined outlined
Section titled "outlined"Whether the control has an outlined appearance.
outlined: boolean pattern
Section titled "pattern"The regular expression the value is validated against.
pattern: string | undefined validateOnly
Section titled "validateOnly"Whether the validation rules apply without restricting user input. The user can type past maxLength,
and the spin buttons of a number input can go past min and max.
validateOnly: boolean Accessors
Section titled "Accessors"selectionEnd
Section titled "selectionEnd"The offset of the end of the text selection, in UTF-16 code units.
null before the first render and for the email and number types.
get selectionEnd(): number | null
Returns number | null
selectionStart
Section titled "selectionStart"The offset of the start of the text selection, in UTF-16 code units.
Equals selectionEnd when no text is selected. null before the first
render and for the email and number types, which have no selection.
get selectionStart(): number | null
Returns number | null
Methods
Section titled "Methods"Removes focus from the control.
blur(): void Returns void
focus
Section titled "focus"Sets focus on the control.
focus(options: FocusOptions): void Parameters
- options:
FocusOptions
Returns void
select
Section titled "select"Selects all the text inside the input.
select(): void Returns void
setRangeText
Section titled "setRangeText"Replaces the text from start to end in the input. Without start and
end, replaces the selected text.
setRangeText(replacement: string, start: number, end: number, selectMode: RangeTextSelectMode): void Parameters
- replacement:
string - start:
number - end:
number - selectMode:
RangeTextSelectMode
Returns void
setSelectionRange
Section titled "setSelectionRange"Sets the text selection range of the control.
setSelectionRange(start: number, end: number, direction: SelectionRangeDirection): void Parameters
- start:
number - end:
number - direction:
SelectionRangeDirection
Returns void
stepDown
Section titled "stepDown"Decrements the numeric value of the input by one or more steps.
stepDown(n: number): void Parameters
- n:
number
Returns void
stepUp
Section titled "stepUp"Increments the numeric value of the input by one or more steps.
stepUp(n: number): void Parameters
- n:
number
Returns void
Events
Section titled "Events"onChange
Section titled "onChange"Emitted when the value of the control is committed.
onChange(args: CustomEvent<string>): void Parameters
- args:
CustomEvent<string>
Returns void
onInput
Section titled "onInput"Emitted when the control input receives user input.
onInput(args: CustomEvent<string>): void Parameters
- args:
CustomEvent<string>