Search field
A search field takes a query, with the search icon already in place, and tells your code as the reader types so it can filter the results. Its input pacing decides how often a search runs: on every keystroke, once typing pauses, at a steady rate, or as often as your search can keep up. Watch the first field below gain and lose a badge, and the second report an error.
Reference docs
Choosing a text field
Seven components share the text field's form. Each suits a different kind of value:
- Text field: one line of free text, such as a name, a title, or a city.
- Text area: several lines of free text, such as a comment, a description, or a delivery note.
- Email field: an email address, which the form checks is well formed before it is sent, with the email keyboard on a phone.
- Password field: a secret the screen hides as it is typed, such as a password or a PIN.
- Number field: an exact number, shown formatted for the reader's locale, such as a quantity, a price, or a percentage.
- Phone number field: a telephone number, with the dial pad on a phone.
- Search field: a query that filters or searches as the reader types, with the search icon in place.
Two jobs belong elsewhere. A choice from a fixed list is a select, and a number picked by feel rather than typed exactly is a slider.
Choosing a variant
Three variants set how much of a container the field draws, from most to least:
- Filled: the shipped default, with the most emphasis; suits the main search of a page, which should stand out among other content.
- Outlined: less emphasis; suits a toolbar or form with several fields, where a lighter box keeps the layout calm.
- Text: no container and no visible label; suits a search that sits inside a frame your layout already draws.
Built in
- The search icon sits in front of the input, so a search needs no icon of its own.
can hold back theinput-event-modeinputevent until typing pauses, release it at a steady rate, or wait as long as the user's typing and your search call for. sets the interval, 300 milliseconds unless you change it. Without a mode,input-rate-limit-delayinputfires on every keystroke. is current on every keystroke; only the event waits.value- Pressing Enter in the field submits its form, so a search needs no separate submit wiring.
offers the search keyboard on a phone unless your app configuration says otherwise.inputmode andbadge-value mark a filtered search without a separate element, in the filled and outlined variants.badge-dot
Using search fields well
- Keep every field in a form or toolbar in one style, either filled or outlined.
- Give every search field a
that names what it searches, such as "Search recipes", and put guidance inlabel .supporting-text - Put a correction in
; it replaces the supporting text while the field is in error.error-text - Slot an icon that acts, such as a clear or voice control, as a button with its own accessible name, and leave icons that only decorate unnamed.
Theming fields
Set one design token and every field of that variant follows it: text fields, text areas, selects, and the email, number, password, search, and telephone fields alike.
--ct-field-filled-*themes filled fields,--ct-field-outlined-*outlined fields, and--ct-field-text-*fields with no container.- A token set on the page, or on any element that contains fields, reaches every field of its variant inside it.
- To restyle search fields only, set the token on the element in your own CSS:
cw-search-field {
--ct-field-outlined-corner-shape: square;
}
The Styling tab lists every token and its default.
These rules follow Material 3 Expressive's guidance for text fields, on material.io.
Variants
The field comes in three variants: filled, outlined, and text. Set variantfilled
The text variant draws no container, no visible label, no supporting text and no counter. Its label
Labels and hints
labelplaceholdersupporting-text
Icons
The field draws its own search icon at the start. Content in the leading-icon slot replaces it. has-leading-icon
For the end of the field, use the trailing-icon slot or trailing-icon-namehas-trailing-icon
Badges
badge-valuebadge-dotbadge-concealed
Forms
The field takes part in forms. It submits valuenamevalue attribute. autocompleteoff to turn the browser's suggestions off.
The preview blocks form submission in some browsers, so this demo acts from the button's click. On your own page, the form submits.
Errors and limits
errorerror-textreportValidity() is called, never while the reader types. requiredminlengthmaxlengthpatternmaxlength
Disabled and read-only
disabledreadonly
Density
densitystandard
The filled variant hides its label at density 2 and above; the label stays the accessible name, so add a placeholder
Input event mode
input-event-modeinput; the four modes are immediate, debounced, throttled and adaptive. Omit it and the field emits on every keystroke, as a native input does. Only the event waits: valuechange is never paced.
immediatepasses the native event through untouched.debouncedemits oneinputonce typing pauses for .input-rate-limit-delaythrottledemits at most oneinputper while typing continues.input-rate-limit-delayadaptivewaits longer for a slow typist or a slow search, and never less than . Event pacing explains how it measures both.input-rate-limit-delay
input-rate-limit-delayasyncSinkinput, in every mode, one call at a time. Because it's a function, only code can set it. sink-duty-cycle
Pick a mode, type a few letters quickly, and watch how far the delivered text trails what you type.
Input mode
inputmodesearchtext when a search takes free text that the search keyboard serves badly.
Text direction
text-directionauto lets the browser pick from the first strong character.
Properties
| Property | Attribute | Type | Description |
|---|---|---|---|
asyncSink | ValueChangeSink | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. | |
autocomplete | autocomplete | string | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
badgeConcealed | badge-concealed | booleandefault false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
badgeDot | badge-dot | booleandefault false | Shows the badge as a small dot with no text, whether or not badgeValue is set. See Badges. |
badgeValue | badge-value | string | The badge's text. While it is empty and badgeDot is not set, no badge renders. Ignored if badgeDot is set. See Badges. |
density | density0, 1, 2, 3, 4 | DensityDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
disabled | disabled | boolean | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
error | error | booleandefault false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
errorText | error-text | string | The error message that replaces supporting text when error is true. If errorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
formread-only | HTMLFormElement | The form the component belongs to, or null when it has none. | |
hasLeadingIcon | has-leading-icon | booleandefault false | Whether the field reserves space for a leading icon. Set automatically from the leading-icon slot and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
hasTrailingIcon | has-trailing-icon | booleandefault false | Whether the field reserves space for a trailing icon. Set automatically from the trailing-icon slot and trailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
inputEventMode | input-event-modeimmediate, adaptive, debounced, throttled | InputEventModeInputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by inputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what asyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
inputMode | inputmodenone, decimal, email, numeric, search, tel, text, url | InputModeInputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no inputmode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
inputRateLimitDelay | input-rate-limit-delay | numberdefault 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
label | label | string | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
labelsread-only | NodeList | The <label> elements associated with the element. | |
maxLength | maxlength | numberdefault -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
minLength | minlength | numberdefault -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
name | name | string | The name the element's value is submitted under with its form. See Forms. |
pattern | pattern | string | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
placeholder | placeholder | string | Placeholder text for when the field is empty. Unlike label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
prefixText | prefix-text | string | An optional prefix to display before the input value. |
readOnly | readonly | booleandefault false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
required | required | booleandefault false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
selectionEnd | number | The position where the text selection ends. | |
selectionStart | number | The position where the text selection starts. | |
sinkDutyCycle | sink-duty-cycle | numberdefault 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
suffixText | suffix-text | string | An optional suffix to display after the input value. |
supportingText | supporting-text | string | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
textDirection | text-direction"", auto, LTR, RTL | TextDirectionTextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
trailingIconName | trailing-icon-name | string | A trailing Material Symbols icon name. This is an alternative to using the trailing-icon slot. If both are provided, the trailing-icon slot will take precedence, and a warning will be logged. See Icons. |
validationMessageread-only | string | The message describing why the element is invalid, or an empty string when it is valid. | |
validityread-only | ValidityState | The element's ValidityState. | |
value | value | string | The field's current value, always as a string. See Forms, Input event mode. |
variant | variantfilled, outlined, text | FieldVariantFieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
willValidateread-only | boolean | Whether the element takes part in constraint validation. False while it is disabled or read-only. |
Slots
| Slot | Description |
|---|---|
container | Custom background content. |
leading-icon | The leading icon, intended for a cw-icon or equivalent. It replaces the built-in search icon. |
trailing-icon | The trailing icon, intended for a cw-icon or equivalent. |
Events
| Event | Type | Detail | Description |
|---|---|---|---|
select | Event | — | Dispatched when the user selects text in the field. It bubbles. |
change | Event | — | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
input | InputEvent | — | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Methods
| Method | Returns | Description |
|---|---|---|
checkValidity() | boolean | Checks the element's validity and returns true if it is valid. If not, it dispatches an invalid event; nothing changes on screen. |
reportValidity() | boolean | Checks the element's validity and returns true if it is valid. If not, it dispatches a cancelable invalid event and, unless a listener cancels it, shows validationMessage as the field's error text and focuses the field. |
reset() | void | Restores the value the value attribute holds, or an empty string, and clears any error reportValidity() showed. |
select() | void | Selects all the text in the field.See MDN: HTMLInputElement.select() and MDN: HTMLTextAreaElement.select(). |
setCustomValidity(error: string) | void | Sets a custom validation message, which makes the element invalid. An empty string clears it. |
setRangeText(replacement: string, start?: number, end?: number, selectionMode?: string) | void | Replaces a range of the field's text and updates value to match. With only a replacement, it replaces the current selection; with a start and end, it replaces that range. |
setSelectionRange(start: number, end: number, direction?: string) | void | Sets the start and end positions of the selection in the field.See MDN: HTMLInputElement.setSelectionRange() and MDN: HTMLTextAreaElement.setSelectionRange(). |
A form reset calls reset().
Props
| Prop | Type | Description |
|---|---|---|
asyncSink | ValueChangeSink | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. |
autocomplete | string | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
badgeConcealed | booleandefault false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
badgeDot | booleandefault false | Shows the badge as a small dot with no text, whether or not badgeValue is set. See Badges. |
badgeValue | string | The badge's text. While it is empty and badgeDot is not set, no badge renders. Ignored if badgeDot is set. See Badges. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
disabled | boolean | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
error | booleandefault false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
errorText | string | The error message that replaces supporting text when error is true. If errorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
formread-only (ref) | HTMLFormElement | The form the component belongs to, or null when it has none. |
hasLeadingIcon | booleandefault false | Whether the field reserves space for a leading icon. Set automatically from the slot="leading-icon" child and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
hasTrailingIcon | booleandefault false | Whether the field reserves space for a trailing icon. Set automatically from the slot="trailing-icon" child and trailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
inputEventMode | InputEventModeTypeInputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by inputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what asyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
inputMode | InputModeTypeInputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no inputMode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
inputRateLimitDelay | numberdefault 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
label | string | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
labelsread-only (ref) | NodeList | The <label> elements associated with the element. |
maxLength | numberdefault -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
minLength | numberdefault -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
name | string | The name the element's value is submitted under with its form. See Forms. |
pattern | string | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
placeholder | string | Placeholder text for when the field is empty. Unlike label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
prefixText | string | An optional prefix to display before the input value. |
readOnly | booleandefault false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
required | booleandefault false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
selectionEndthrough the ref | number | The position where the text selection ends. |
selectionStartthrough the ref | number | The position where the text selection starts. |
sinkDutyCycle | numberdefault 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
suffixText | string | An optional suffix to display after the input value. |
supportingText | string | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
textDirection | TextDirectionTypeTextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
trailingIconName | string | A trailing Material Symbols icon name. This is an alternative to using the slot="trailing-icon" child. If both are provided, the slot="trailing-icon" child will take precedence, and a warning will be logged. See Icons. |
validationMessageread-only (ref) | string | The message describing why the element is invalid, or an empty string when it is valid. |
validityread-only (ref) | ValidityState | The element's ValidityState. |
value | string | The field's current value, always as a string. See Forms, Input event mode. |
variant | FieldVariantTypeFieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
willValidateread-only (ref) | boolean | Whether the element takes part in constraint validation. False while it is disabled or read-only. |
Children
| Child | Description |
|---|---|
a child with slot="container" | Custom background content. |
a child with slot="leading-icon" | The leading icon, intended for a CrIcon or equivalent. It replaces the built-in search icon. |
a child with slot="trailing-icon" | The trailing icon, intended for a CrIcon or equivalent. |
Events
| Prop | Argument | Description |
|---|---|---|
onSelect | Event | Dispatched when the user selects text in the field. It bubbles. |
onChange | React.ChangeEvent<HTMLInputElement> | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
onInput | React.ChangeEvent<HTMLInputElement> | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Methods
Call these on the element the ref holds.
| Method | Returns | Description |
|---|---|---|
checkValidity() | boolean | Checks the element's validity and returns true if it is valid. If not, it dispatches an invalid event; nothing changes on screen. |
reportValidity() | boolean | Checks the element's validity and returns true if it is valid. If not, it dispatches a cancelable invalid event and, unless a listener cancels it, shows validationMessage as the field's error text and focuses the field. |
reset() | void | Restores the value the value attribute holds, or an empty string, and clears any error reportValidity() showed. |
select() | void | Selects all the text in the field.See MDN: HTMLInputElement.select() and MDN: HTMLTextAreaElement.select(). |
setCustomValidity(error: string) | void | Sets a custom validation message, which makes the element invalid. An empty string clears it. |
setRangeText(replacement: string, start?: number, end?: number, selectionMode?: string) | void | Replaces a range of the field's text and updates value to match. With only a replacement, it replaces the current selection; with a start and end, it replaces that range. |
setSelectionRange(start: number, end: number, direction?: string) | void | Sets the start and end positions of the selection in the field.See MDN: HTMLInputElement.setSelectionRange() and MDN: HTMLTextAreaElement.setSelectionRange(). |
A form reset calls reset().
Parameters
| Parameter | Type | Description |
|---|---|---|
AsyncSink | ValueChangeSink? | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. |
Autocomplete | string? | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
BadgeConcealed | bool?default false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
BadgeDot | bool?default false | Shows the badge as a small dot with no text, whether or not BadgeValue is set. See Badges. |
BadgeValue | string? | The badge's text. While it is empty and BadgeDot is not set, no badge renders. Ignored if BadgeDot is set. See Badges. |
Density | Density?Density.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
Disabled | bool? | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
Error | bool?default false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
ErrorText | string? | The error message that replaces supporting text when Error is true. If ErrorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
HasLeadingIcon | bool?default false | Whether the field reserves space for a leading icon. Set automatically from the LeadingIcon render fragment and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
HasTrailingIcon | bool?default false | Whether the field reserves space for a trailing icon. Set automatically from the TrailingIcon render fragment and TrailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
InputEventMode | InputEventMode?InputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by InputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what AsyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
InputMode | InputMode?InputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no InputMode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
InputRateLimitDelay | int?default 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
Label | string? | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
MaxLength | int?default -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
MinLength | int?default -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
Name | string? | The name the element's value is submitted under with its form. See Forms. |
Pattern | string? | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
Placeholder | string? | Placeholder text for when the field is empty. Unlike Label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
PrefixText | string? | An optional prefix to display before the input value. |
ReadOnly | bool?default false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
Required | bool?default false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
SinkDutyCycle | double?default 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
SuffixText | string? | An optional suffix to display after the input value. |
SupportingText | string? | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
TextDirection | TextDirection?TextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
TrailingIconName | string? | A trailing Material Symbols icon name. This is an alternative to using the TrailingIcon render fragment. If both are provided, the TrailingIcon render fragment will take precedence, and a warning will be logged. See Icons. |
Value | string? | The field's current value, always as a string. See Forms, Input event mode. |
ValueExpression | Expression<Func<string>>? | Gets or sets an expression that identifies the bound value. |
Variant | FieldVariant?FieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
Render fragments
| Parameter | Type | Description |
|---|---|---|
Container | RenderFragment? | Custom background content. |
LeadingIcon | RenderFragment? | The leading icon, intended for a CbIcon or equivalent. It replaces the built-in search icon. |
TrailingIcon | RenderFragment? | The trailing icon, intended for a CbIcon or equivalent. |
Event callbacks
| Parameter | Type | Description |
|---|---|---|
OnSelect | EventCallback | Dispatched when the user selects text in the field. It bubbles. |
OnChange | EventCallback<ChangeEventArgs> | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
OnInput | EventCallback<ChangeEventArgs> | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Inputs
| Input | Type | Description |
|---|---|---|
asyncSink | ValueChangeSink | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. |
autocomplete | string | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
badgeConcealed | booleandefault false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
badgeDot | booleandefault false | Shows the badge as a small dot with no text, whether or not badgeValue is set. See Badges. |
badgeValue | string | The badge's text. While it is empty and badgeDot is not set, no badge renders. Ignored if badgeDot is set. See Badges. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
disabled | boolean | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
error | booleandefault false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
errorText | string | The error message that replaces supporting text when error is true. If errorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
hasLeadingIcon | booleandefault false | Whether the field reserves space for a leading icon. Set automatically from the leading-icon slot and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
hasTrailingIcon | booleandefault false | Whether the field reserves space for a trailing icon. Set automatically from the trailing-icon slot and trailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
inputEventMode | InputEventModeTypeInputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by inputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what asyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
inputMode | InputModeTypeInputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no inputMode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
inputRateLimitDelay | numberdefault 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
label | string | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
maxLength | numberdefault -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
minLength | numberdefault -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
name | string | The name the element's value is submitted under with its form. See Forms. |
pattern | string | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
placeholder | string | Placeholder text for when the field is empty. Unlike label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
prefixText | string | An optional prefix to display before the input value. |
readOnly | booleandefault false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
required | booleandefault false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
sinkDutyCycle | numberdefault 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
suffixText | string | An optional suffix to display after the input value. |
supportingText | string | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
textDirection | TextDirectionTypeTextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
trailingIconName | string | A trailing Material Symbols icon name. This is an alternative to using the trailing-icon slot. If both are provided, the trailing-icon slot will take precedence, and a warning will be logged. See Icons. |
value | string | The field's current value, always as a string. See Forms, Input event mode. |
variant | FieldVariantTypeFieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
Content projection
| Content | Description |
|---|---|
an element with slot="container" | Custom background content. |
an element with slot="leading-icon" | The leading icon, intended for a CaIcon or equivalent. It replaces the built-in search icon. |
an element with slot="trailing-icon" | The trailing icon, intended for a CaIcon or equivalent. |
Outputs
| Output | Event | Description |
|---|---|---|
cwSelect | Event | Dispatched when the user selects text in the field. It bubbles. |
cwChange | Event | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
cwInput | InputEvent | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Props
| Prop | Type | Description |
|---|---|---|
asyncSink | ValueChangeSink | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. |
autocomplete | string | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
badgeConcealed | booleandefault false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
badgeDot | booleandefault false | Shows the badge as a small dot with no text, whether or not badgeValue is set. See Badges. |
badgeValue | string | The badge's text. While it is empty and badgeDot is not set, no badge renders. Ignored if badgeDot is set. See Badges. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
disabled | boolean | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
error | booleandefault false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
errorText | string | The error message that replaces supporting text when error is true. If errorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
hasLeadingIcon | booleandefault false | Whether the field reserves space for a leading icon. Set automatically from the leading-icon slot and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
hasTrailingIcon | booleandefault false | Whether the field reserves space for a trailing icon. Set automatically from the trailing-icon slot and trailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
inputEventMode | InputEventModeTypeInputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by inputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what asyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
inputMode | InputModeTypeInputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no inputMode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
inputRateLimitDelay | numberdefault 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
label | string | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
maxLength | numberdefault -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
minLength | numberdefault -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
name | string | The name the element's value is submitted under with its form. See Forms. |
pattern | string | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
placeholder | string | Placeholder text for when the field is empty. Unlike label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
prefixText | string | An optional prefix to display before the input value. |
readOnly | booleandefault false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
required | booleandefault false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
sinkDutyCycle | numberdefault 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
suffixText | string | An optional suffix to display after the input value. |
supportingText | string | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
textDirection | TextDirectionTypeTextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
trailingIconName | string | A trailing Material Symbols icon name. This is an alternative to using the trailing-icon slot. If both are provided, the trailing-icon slot will take precedence, and a warning will be logged. See Icons. |
value | string | The field's current value, always as a string. See Forms, Input event mode. |
variant | FieldVariantTypeFieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
Slots
| Slot | Description |
|---|---|
container | Custom background content. |
leading-icon | The leading icon, intended for a CvIcon or equivalent. It replaces the built-in search icon. |
trailing-icon | The trailing icon, intended for a CvIcon or equivalent. |
Events
| Event | Type | Description |
|---|---|---|
select | Event | Dispatched when the user selects text in the field. It bubbles. |
change | Event | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
input | InputEvent | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Props
| Prop | Type | Description |
|---|---|---|
asyncSink | ValueChangeSink | The async work, such as a request to a server, that the field paces input against. It is called whenever the field delivers an input event, in every mode, and Adaptive also uses it to set how soon the next one comes. A slow sink is asked less often, and is not called once per keystroke. Read the field's value inside it, as an input listener would. See Input event mode. |
autocomplete | string | Describes what, if any, type of autocomplete functionality the input should provide.See MDN: autocomplete attribute. See Forms. |
badgeConcealed | booleandefault false | Hides the badge while keeping its value and dot setting, so clearing this property shows the same badge again. See Badges. |
badgeDot | booleandefault false | Shows the badge as a small dot with no text, whether or not badgeValue is set. See Badges. |
badgeValue | string | The badge's text. While it is empty and badgeDot is not set, no badge renders. Ignored if badgeDot is set. See Badges. |
density | DensityTypeDensity.Standard, .Dense1, .Dense2, .Dense3, .Dense4default Density.Standard, from the style configuration | The field's density level.Ignored for Text variants. See Density. |
disabled | boolean | Whether the element is disabled. Also reads true while a disabled <fieldset> contains it. See Disabled and read-only. |
error | booleandefault false | Shows the field in its error state and marks the input invalid for assistive technology.This error state overrides the error state controlled by reportValidity(). See Errors and limits. |
errorText | string | The error message that replaces supporting text when error is true. If errorText is an empty string, then the supporting text will continue to show.This error message overrides the error message displayed by reportValidity(). See Errors and limits. |
hasLeadingIcon | booleandefault false | Whether the field reserves space for a leading icon. Set automatically from the leadingIconSnippet snippet and leadingIconName; set it yourself only when the field is rendered on the server. See Icons. |
hasTrailingIcon | booleandefault false | Whether the field reserves space for a trailing icon. Set automatically from the trailingIconSnippet snippet and trailingIconName; set it yourself only when the field is rendered on the server. See Icons. |
inputEventMode | InputEventModeTypeInputEventMode.Immediate, .Adaptive, .Debounced, .Throttleddefault InputEventMode.Immediate | When the field fires input. Debounced and Throttled pace it by inputRateLimitDelay, and Adaptive paces it to the user's own typing rhythm and to what asyncSink can keep up with. A cleared or unrecognized value is treated as the field's default. See Input event mode. |
inputMode | InputModeTypeInputMode.None, .Decimal, .Email, .Numeric, .Search, .Tel, .Text, .Urldefault InputMode.Search, from the app configuration | The virtual keyboard to offer on a touch screen. With no inputMode attribute, the field's default input mode applies, which the application configuration can change. See Input mode. |
inputRateLimitDelay | numberdefault 300 | The pacing interval for input, in milliseconds: the pause after the last keystroke for Debounced, the minimum gap between events for Throttled, and the shortest allowed pause for Adaptive. Immediate ignores it. A value that is not a finite number is treated as the default, and a negative one as 0. See Input event mode. |
label | string | The field's label, which rests in the input's place and floats above it when the field has focus or a value. It is also the input's accessible name unless aria-label is set. Hidden in the filled variant at density 2 and above, where it is only the accessible name.Learn more about floating labels from the Material Design 3: text fields guidelines.For Text variants, only sets the ARIA label. See Variants, Labels and hints. |
maxLength | numberdefault -1 | The most characters the field accepts, or -1 for no limit. When set, a character counter shows below the field and is read as part of its description.See MDN: input maxlength attribute. See Errors and limits. |
minLength | numberdefault -1 | The fewest characters the value may have to pass constraint validation, checked once the user has edited it. Set to -1 for none.See MDN: input minlength attribute. See Errors and limits. |
name | string | The name the element's value is submitted under with its form. See Forms. |
pattern | string | A regular expression that the field's value must match to pass constraint validation.See MDN: input pattern attribute. See Errors and limits. |
placeholder | string | Placeholder text for when the field is empty. Unlike label, the placeholder never floats, and it is hidden once the field has a value.See MDN: placeholder attribute. See Labels and hints, Density. |
prefixText | string | An optional prefix to display before the input value. |
readOnly | booleandefault false | Indicates whether or not a user should be able to edit the field's value.See MDN: input readonly attribute. See Disabled and read-only. |
required | booleandefault false | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty. Additionally the floating label will render an asterisk "*" when true.See MDN: required attribute. See Errors and limits. |
sinkDutyCycle | numberdefault 1 | The share of the sink's time this field may occupy, above 0 and up to 1, in every input event mode. At 1 the next call goes out as soon as the last one finishes; at 0.25 the field leaves three quarters of the time idle. A value below 0.01 is treated as 0.01, and an assignment outside the range is ignored. See Input event mode. |
suffixText | string | An optional suffix to display after the input value. |
supportingText | string | Conveys additional information below the field, such as how it should be used. The text variant does not show it, but still reads it as part of the input's description. See Labels and hints. |
textDirection | TextDirectionTypeTextDirection.Default, .Auto, .LTR, .RTLdefault TextDirection.Default | Override the input text CSS direction. Useful for RTL languages that use LTR notation for fractions. See Text direction. |
trailingIconName | string | A trailing Material Symbols icon name. This is an alternative to using the trailingIconSnippet snippet. If both are provided, the trailingIconSnippet snippet will take precedence, and a warning will be logged. See Icons. |
value | string | The field's current value, always as a string. See Forms, Input event mode. |
variant | FieldVariantTypeFieldVariant.Filled, .Outlined, .Textdefault FieldVariant.Filled, from the style configuration | The field's variant. Unset, the style configuration's default field variant applies, else Filled. See Variants. |
Snippets
| Snippet | Description |
|---|---|
containerSnippet | Custom background content. |
leadingIconSnippet | The leading icon, intended for a CsIcon or equivalent. It replaces the built-in search icon. |
trailingIconSnippet | The trailing icon, intended for a CsIcon or equivalent. |
Events
| Prop | Type | Description |
|---|---|---|
onSelect | Event | Dispatched when the user selects text in the field. It bubbles. |
onChange | Event | Dispatched when the user commits a change to the value, such as by leaving the field after editing it. It bubbles. |
onInput | InputEvent | Dispatched each time the user edits the value. It bubbles and is composed. |
change and select are never paced. Enter delivers a held input first, then change, then submits the owning form.
Each attribute value has its own tokens; a cell shows its token's value, and selecting the cell shows the token's fallback path, with each name and value ready to copy. For example, the filled column's active-indicator-color row is --ct-field-filled-active-indicator-color, which defaults to --ct-sys-color-on-surface-variant.
Variant
| Name | filled | outlined | text |
|---|---|---|---|
active-indicator-color | --ct-sys-color-on-surface-variant --ct-field-filled-active-indicator-color | — | — |
active-indicator-height | 1px --ct-field-filled-active-indicator-height | — | — |
bottom-space | 16px --ct-field-filled-bottom-space | 16px --ct-field-outlined-bottom-space | — |
caret-color | --ct-sys-color-primary --ct-field-filled-caret-color | --ct-sys-color-primary --ct-field-outlined-caret-color | --ct-sys-color-primary --ct-field-text-caret-color |
container-color | --ct-sys-color-surface-container-highest --ct-field-filled-container-color | — | — |
container-end-end-radius | — | --ct-sys-corner-radius-extra-small --ct-field-outlined-container-end-end-radius | — |
container-end-start-radius | — | --ct-sys-corner-radius-extra-small --ct-field-outlined-container-end-start-radius | — |
container-start-end-radius | --ct-sys-corner-radius-extra-small --ct-field-filled-container-start-end-radius | --ct-sys-corner-radius-extra-small --ct-field-outlined-container-start-end-radius | — |
container-start-start-radius | --ct-sys-corner-radius-extra-small --ct-field-filled-container-start-start-radius | --ct-sys-corner-radius-extra-small --ct-field-outlined-container-start-start-radius | — |
content-color | --ct-sys-color-on-surface --ct-field-filled-content-color | --ct-sys-color-on-surface --ct-field-outlined-content-color | --ct-sys-color-on-surface --ct-field-text-content-color |
content-font | --ct-sys-typescale-body-large-font --ct-field-filled-content-font | --ct-sys-typescale-body-large-font --ct-field-outlined-content-font | --ct-sys-typescale-body-large-font --ct-field-text-content-font |
content-line-height | --ct-sys-typescale-body-large-line-height --ct-field-filled-content-line-height | --ct-sys-typescale-body-large-line-height --ct-field-outlined-content-line-height | --ct-sys-typescale-body-large-line-height --ct-field-text-content-line-height |
content-placeholder-color | --ct-sys-color-on-surface-variant --ct-field-filled-content-placeholder-color | --ct-sys-color-on-surface-variant --ct-field-outlined-content-placeholder-color | --ct-sys-color-on-surface-variant --ct-field-text-content-placeholder-color |
content-prefix-color | --ct-sys-color-on-surface-variant --ct-field-filled-content-prefix-color | --ct-sys-color-on-surface-variant --ct-field-outlined-content-prefix-color | --ct-sys-color-on-surface-variant --ct-field-text-content-prefix-color |
content-prefix-trailing-space | 2px --ct-field-filled-content-prefix-trailing-space | 2px --ct-field-outlined-content-prefix-trailing-space | 2px --ct-field-text-content-prefix-trailing-space |
content-size | --ct-sys-typescale-body-large-size --ct-field-filled-content-size | --ct-sys-typescale-body-large-size --ct-field-outlined-content-size | --ct-sys-typescale-body-large-size --ct-field-text-content-size |
content-space | 16px --ct-field-filled-content-space | 16px --ct-field-outlined-content-space | — |
content-suffix-color | --ct-sys-color-on-surface-variant --ct-field-filled-content-suffix-color | --ct-sys-color-on-surface-variant --ct-field-outlined-content-suffix-color | --ct-sys-color-on-surface-variant --ct-field-text-content-suffix-color |
content-suffix-leading-space | 2px --ct-field-filled-content-suffix-leading-space | 2px --ct-field-outlined-content-suffix-leading-space | 2px --ct-field-text-content-suffix-leading-space |
content-tracking | --ct-sys-typescale-body-large-tracking --ct-field-filled-content-tracking | --ct-sys-typescale-body-large-tracking --ct-field-outlined-content-tracking | --ct-sys-typescale-body-large-tracking --ct-field-text-content-tracking |
content-weight | --ct-sys-typescale-body-large-weight --ct-field-filled-content-weight | --ct-sys-typescale-body-large-weight --ct-field-outlined-content-weight | --ct-sys-typescale-body-large-weight --ct-field-text-content-weight |
label-text-color | --ct-sys-color-on-surface-variant --ct-field-filled-label-text-color | --ct-sys-color-on-surface-variant --ct-field-outlined-label-text-color | — |
label-text-font | --ct-sys-typescale-body-large-font --ct-field-filled-label-text-font | --ct-sys-typescale-body-large-font --ct-field-outlined-label-text-font | — |
label-text-line-height | --ct-sys-typescale-body-large-line-height --ct-field-filled-label-text-line-height | --ct-sys-typescale-body-large-line-height --ct-field-outlined-label-text-line-height | — |
label-text-padding-bottom | — | 8px --ct-field-outlined-label-text-padding-bottom | — |
label-text-populated-line-height | --ct-sys-typescale-body-small-line-height --ct-field-filled-label-text-populated-line-height | --ct-sys-typescale-body-small-line-height --ct-field-outlined-label-text-populated-line-height | — |
label-text-populated-size | --ct-sys-typescale-body-small-size --ct-field-filled-label-text-populated-size | --ct-sys-typescale-body-small-size --ct-field-outlined-label-text-populated-size | — |
label-text-size | --ct-sys-typescale-body-large-size --ct-field-filled-label-text-size | --ct-sys-typescale-body-large-size --ct-field-outlined-label-text-size | — |
label-text-weight | --ct-sys-typescale-body-large-weight --ct-field-filled-label-text-weight | --ct-sys-typescale-body-large-weight --ct-field-outlined-label-text-weight | — |
leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-leading-content-color | — |
leading-content-size | 24px --ct-field-filled-leading-content-size | 24px --ct-field-outlined-leading-content-size | 24px --ct-field-text-leading-content-size |
leading-space | 16px --ct-field-filled-leading-space | 16px --ct-field-outlined-leading-space | — |
outline-color | — | --ct-sys-color-outline --ct-field-outlined-outline-color | — |
outline-label-padding | — | 4px --ct-field-outlined-outline-label-padding | — |
outline-width | — | 1px --ct-field-outlined-outline-width | — |
supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-filled-supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-outlined-supporting-text-color | — |
supporting-text-font | --ct-sys-typescale-body-small-font --ct-field-filled-supporting-text-font | --ct-sys-typescale-body-small-font --ct-field-outlined-supporting-text-font | — |
supporting-text-leading-space | 16px --ct-field-filled-supporting-text-leading-space | 16px --ct-field-outlined-supporting-text-leading-space | — |
supporting-text-line-height | --ct-sys-typescale-body-small-line-height --ct-field-filled-supporting-text-line-height | --ct-sys-typescale-body-small-line-height --ct-field-outlined-supporting-text-line-height | — |
supporting-text-size | --ct-sys-typescale-body-small-size --ct-field-filled-supporting-text-size | --ct-sys-typescale-body-small-size --ct-field-outlined-supporting-text-size | — |
supporting-text-top-space | 4px --ct-field-filled-supporting-text-top-space | 4px --ct-field-outlined-supporting-text-top-space | — |
supporting-text-tracking | --ct-sys-typescale-body-small-tracking --ct-field-filled-supporting-text-tracking | --ct-sys-typescale-body-small-tracking --ct-field-outlined-supporting-text-tracking | — |
supporting-text-trailing-space | 16px --ct-field-filled-supporting-text-trailing-space | 16px --ct-field-outlined-supporting-text-trailing-space | — |
supporting-text-weight | --ct-sys-typescale-body-small-weight --ct-field-filled-supporting-text-weight | --ct-sys-typescale-body-small-weight --ct-field-outlined-supporting-text-weight | — |
top-space | 16px --ct-field-filled-top-space | 16px --ct-field-outlined-top-space | — |
trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-trailing-content-color | — |
trailing-content-size | 24px --ct-field-filled-trailing-content-size | 24px --ct-field-outlined-trailing-content-size | 24px --ct-field-text-trailing-content-size |
trailing-space | 16px --ct-field-filled-trailing-space | 16px --ct-field-outlined-trailing-space | — |
with-label-bottom-space | 8px --ct-field-filled-with-label-bottom-space | — | — |
with-label-top-space | 8px --ct-field-filled-with-label-top-space | — | — |
with-leading-content-leading-space | 12px --ct-field-filled-with-leading-content-leading-space | 12px --ct-field-outlined-with-leading-content-leading-space | — |
with-trailing-content-trailing-space | 12px --ct-field-filled-with-trailing-content-trailing-space | 12px --ct-field-outlined-with-trailing-content-trailing-space | — |
hover-active-indicator-color | --ct-sys-color-on-surface --ct-field-filled-hover-active-indicator-color | — | — |
hover-active-indicator-height | 1px --ct-field-filled-hover-active-indicator-height | — | — |
hover-content-color | --ct-sys-color-on-surface --ct-field-filled-hover-content-color | --ct-sys-color-on-surface --ct-field-outlined-hover-content-color | — |
hover-label-text-color | --ct-sys-color-on-surface-variant --ct-field-filled-hover-label-text-color | --ct-sys-color-on-surface-variant --ct-field-outlined-hover-label-text-color | — |
hover-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-hover-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-hover-leading-content-color | — |
hover-outline-color | — | --ct-sys-color-on-surface --ct-field-outlined-hover-outline-color | — |
hover-outline-width | — | 1px --ct-field-outlined-hover-outline-width | — |
hover-state-layer-color | --ct-sys-color-on-surface --ct-field-filled-hover-state-layer-color | --ct-sys-color-on-surface --ct-field-outlined-hover-state-layer-color | — |
hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-field-filled-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-field-outlined-hover-state-layer-opacity | — |
hover-supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-filled-hover-supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-outlined-hover-supporting-text-color | — |
hover-trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-hover-trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-hover-trailing-content-color | — |
focus-active-indicator-color | --ct-sys-color-primary --ct-field-filled-focus-active-indicator-color | — | — |
focus-active-indicator-height | 3px --ct-field-filled-focus-active-indicator-height | — | — |
focus-caret-color | --ct-sys-color-primary --ct-field-filled-focus-caret-color | --ct-sys-color-primary --ct-field-outlined-focus-caret-color | --ct-sys-color-primary --ct-field-text-focus-caret-color |
focus-content-color | --ct-sys-color-on-surface --ct-field-filled-focus-content-color | --ct-sys-color-on-surface --ct-field-outlined-focus-content-color | — |
focus-label-text-color | --ct-sys-color-primary --ct-field-filled-focus-label-text-color | --ct-sys-color-primary --ct-field-outlined-focus-label-text-color | — |
focus-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-focus-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-focus-leading-content-color | — |
focus-outline-color | — | --ct-sys-color-primary --ct-field-outlined-focus-outline-color | --ct-sys-color-primary --ct-field-text-focus-outline-color |
focus-outline-width | — | 2px --ct-field-outlined-focus-outline-width | 2px --ct-field-text-focus-outline-width |
focus-supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-filled-focus-supporting-text-color | --ct-sys-color-on-surface-variant --ct-field-outlined-focus-supporting-text-color | — |
focus-trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-focus-trailing-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-focus-trailing-content-color | — |
disabled-active-indicator-color | --ct-sys-color-on-surface --ct-field-filled-disabled-active-indicator-color | — | — |
disabled-active-indicator-height | 1px --ct-field-filled-disabled-active-indicator-height | — | — |
disabled-active-indicator-opacity | 0.38 --ct-field-filled-disabled-active-indicator-opacity | — | — |
disabled-container-color | --ct-sys-color-on-surface --ct-field-filled-disabled-container-color | — | — |
disabled-container-opacity | 0.04 --ct-field-filled-disabled-container-opacity | — | — |
disabled-content-color | --ct-sys-color-on-surface --ct-field-filled-disabled-content-color | --ct-sys-color-on-surface --ct-field-outlined-disabled-content-color | --ct-sys-color-on-surface --ct-field-text-disabled-content-color |
disabled-content-opacity | 0.38 --ct-field-filled-disabled-content-opacity | 0.38 --ct-field-outlined-disabled-content-opacity | 0.38 --ct-field-text-disabled-content-opacity |
disabled-label-text-color | --ct-sys-color-on-surface --ct-field-filled-disabled-label-text-color | --ct-sys-color-on-surface --ct-field-outlined-disabled-label-text-color | — |
disabled-label-text-opacity | 0.38 --ct-field-filled-disabled-label-text-opacity | 0.38 --ct-field-outlined-disabled-label-text-opacity | — |
disabled-leading-content-color | --ct-sys-color-on-surface --ct-field-filled-disabled-leading-content-color | --ct-sys-color-on-surface --ct-field-outlined-disabled-leading-content-color | — |
disabled-leading-content-opacity | 0.38 --ct-field-filled-disabled-leading-content-opacity | 0.38 --ct-field-outlined-disabled-leading-content-opacity | — |
disabled-outline-color | — | --ct-sys-color-on-surface --ct-field-outlined-disabled-outline-color | — |
disabled-outline-opacity | — | 0.12 --ct-field-outlined-disabled-outline-opacity | — |
disabled-outline-width | — | 1px --ct-field-outlined-disabled-outline-width | — |
disabled-supporting-text-color | --ct-sys-color-on-surface --ct-field-filled-disabled-supporting-text-color | --ct-sys-color-on-surface --ct-field-outlined-disabled-supporting-text-color | — |
disabled-supporting-text-opacity | 0.38 --ct-field-filled-disabled-supporting-text-opacity | 0.38 --ct-field-outlined-disabled-supporting-text-opacity | — |
disabled-trailing-content-color | --ct-sys-color-on-surface --ct-field-filled-disabled-trailing-content-color | --ct-sys-color-on-surface --ct-field-outlined-disabled-trailing-content-color | — |
disabled-trailing-content-opacity | 0.38 --ct-field-filled-disabled-trailing-content-opacity | 0.38 --ct-field-outlined-disabled-trailing-content-opacity | — |
error-active-indicator-color | --ct-sys-color-error --ct-field-filled-error-active-indicator-color | — | — |
error-content-color | --ct-sys-color-on-surface --ct-field-filled-error-content-color | --ct-sys-color-on-surface --ct-field-outlined-error-content-color | --ct-sys-color-on-surface --ct-field-text-error-content-color |
error-focus-active-indicator-color | --ct-sys-color-error --ct-field-filled-error-focus-active-indicator-color | — | — |
error-focus-caret-color | --ct-sys-color-error --ct-field-filled-error-focus-caret-color | --ct-sys-color-error --ct-field-outlined-error-focus-caret-color | --ct-sys-color-error --ct-field-text-error-focus-caret-color |
error-focus-content-color | --ct-sys-color-on-surface --ct-field-filled-error-focus-content-color | --ct-sys-color-on-surface --ct-field-outlined-error-focus-content-color | — |
error-focus-label-text-color | --ct-sys-color-error --ct-field-filled-error-focus-label-text-color | --ct-sys-color-error --ct-field-outlined-error-focus-label-text-color | — |
error-focus-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-error-focus-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-error-focus-leading-content-color | — |
error-focus-outline-color | — | --ct-sys-color-error --ct-field-outlined-error-focus-outline-color | --ct-sys-color-error --ct-field-text-error-focus-outline-color |
error-focus-supporting-text-color | --ct-sys-color-error --ct-field-filled-error-focus-supporting-text-color | --ct-sys-color-error --ct-field-outlined-error-focus-supporting-text-color | — |
error-focus-trailing-content-color | --ct-sys-color-error --ct-field-filled-error-focus-trailing-content-color | --ct-sys-color-error --ct-field-outlined-error-focus-trailing-content-color | — |
error-hover-active-indicator-color | --ct-sys-color-on-error-container --ct-field-filled-error-hover-active-indicator-color | — | — |
error-hover-content-color | --ct-sys-color-on-surface --ct-field-filled-error-hover-content-color | --ct-sys-color-on-surface --ct-field-outlined-error-hover-content-color | — |
error-hover-label-text-color | --ct-sys-color-on-error-container --ct-field-filled-error-hover-label-text-color | --ct-sys-color-on-error-container --ct-field-outlined-error-hover-label-text-color | — |
error-hover-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-error-hover-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-error-hover-leading-content-color | — |
error-hover-outline-color | — | --ct-sys-color-on-error-container --ct-field-outlined-error-hover-outline-color | — |
error-hover-state-layer-color | --ct-sys-color-on-surface --ct-field-filled-error-hover-state-layer-color | — | — |
error-hover-state-layer-opacity | --ct-sys-state-hover-state-layer-opacity --ct-field-filled-error-hover-state-layer-opacity | — | — |
error-hover-supporting-text-color | --ct-sys-color-on-error-container --ct-field-filled-error-hover-supporting-text-color | --ct-sys-color-on-error-container --ct-field-outlined-error-hover-supporting-text-color | — |
error-hover-trailing-content-color | --ct-sys-color-on-error-container --ct-field-filled-error-hover-trailing-content-color | --ct-sys-color-on-error-container --ct-field-outlined-error-hover-trailing-content-color | — |
error-label-text-color | --ct-sys-color-error --ct-field-filled-error-label-text-color | --ct-sys-color-error --ct-field-outlined-error-label-text-color | — |
error-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-filled-error-leading-content-color | --ct-sys-color-on-surface-variant --ct-field-outlined-error-leading-content-color | — |
error-outline-color | — | --ct-sys-color-error --ct-field-outlined-error-outline-color | — |
error-supporting-text-color | --ct-sys-color-error --ct-field-filled-error-supporting-text-color | --ct-sys-color-error --ct-field-outlined-error-supporting-text-color | — |
error-trailing-content-color | --ct-sys-color-error --ct-field-filled-error-trailing-content-color | --ct-sys-color-error --ct-field-outlined-error-trailing-content-color | — |
Names and states
The field's role is searchbox. No WAI-ARIA Authoring Practices pattern governs it, because it behaves like a plain text box.
- The accessible name is the
aria-labelwhen set, and otherwise .label never names the field.placeholder aria-labelis the only ARIA attribute that changes what a screen reader announces. Any otheraria-*attribute you set,aria-describedbyincluded, has no effect.- The description is
, orsupporting-text while the field is in error, followed by the character counter whenerror-text is set.maxlength - The field is announced as invalid in the error state, which
or a reported validation error sets. In the filled and outlined variants, error text is announced when it appears.error is announced as required and adds an asterisk to the visible label. Do not write the asterisk yourself.required- Screen readers skip the search icon, so it never names the field. Put an icon that acts, such as a clear button, in the
trailing-iconslot as a button with its own accessible name. - The field has no clear button. If you want one, add it as a button in the
trailing-iconslot. - A badge is visual only. It adds nothing to the field's name or description.
- Wrap a page-wide search in a
searchlandmark, as in WAI-ARIA Authoring Practices: Search landmark, so assistive technology users can jump to it. - For a single line of text that is not a search, a text field suits the job better.
Keyboard and focus
| Key | Action |
|---|---|
| Tab | Moves focus into the field, then on to the next focusable element. |
| Shift+Tab | Moves focus back to the previous focusable element. |
| Enter | Delivers any held input event, fires change if the text was edited, then submits the owning form. Does nothing without a form. |
| Letters, Backspace, Delete, the arrow keys, Home, and End | Edit the text and move the caret. |
Typing, caret movement, and selection follow the platform. Enter pressed during IME composition (input-method text entry) is left to the input method.
- Focus shows as a thicker active indicator in the filled variant, a thicker outline in the outlined variant, and a focus ring in the text variant.
removes the field from the Tab order, and a disableddisabled<fieldset>around it does the same.- A read-only field keeps its focus and its text selection.
- Reporting a validation error focuses the field, or the form's first invalid field.
Pointer and touch
The filled and outlined variants are 56 pixels tall at the default density. At the densest setting, density
Display settings
- In forced-colors mode, a disabled field's label, content, supporting text and indicator take
GrayText, the outlined border is redrawn as a real border, and the text variant's focus ring isHighlight. - The label's float between its resting and floating positions animates for 150 milliseconds, whatever the reduced-motion setting.
- Set
totext-directionRTLorautofor input in a right-to-left language.
Standards
With its defaults, the search field meets three WCAG 2.2 success criteria:
Four more depend on how you use it:
- 1.1.1 Non-text Content (A): give a slotted image an alt, or mark a decorative one.
- 3.3.1 Error Identification (A): put the message that says what is wrong in
.error-text - 3.3.2 Labels or Instructions (A): set
to say what the field searches.label - 4.1.2 Name, Role, Value (A): give a slotted icon button its own accessible name.