@material/web
Version:
Material web components
358 lines (357 loc) • 11.9 kB
TypeScript
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { LitElement, PropertyValues } from 'lit';
import { StaticValue } from 'lit/static-html.js';
/**
* Input types that are compatible with the text field.
*/
export type TextFieldType = 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'url' | 'textarea';
/**
* Input types that are not fully supported for the text field.
*/
export type UnsupportedTextFieldType = 'color' | 'date' | 'datetime-local' | 'file' | 'month' | 'time' | 'week';
/**
* Input types that are incompatible with the text field.
*/
export type InvalidTextFieldType = 'button' | 'checkbox' | 'hidden' | 'image' | 'radio' | 'range' | 'reset' | 'submit';
/**
* A text field component.
*/
export declare abstract class TextField extends LitElement {
/** @nocollapse */
static shadowRootOptions: ShadowRootInit;
/** @nocollapse */
static readonly formAssociated = true;
disabled: boolean;
/**
* Gets or sets whether or not the text field is in a visually invalid state.
*
* This error state overrides the error state controlled by
* `reportValidity()`.
*/
error: boolean;
/**
* 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()`.
*/
errorText: string;
label: string;
required: boolean;
/**
* The current value of the text field. It is always a string.
*/
value: string;
/**
* An optional prefix to display before the input value.
*/
prefixText: string;
/**
* An optional suffix to display after the input value.
*/
suffixText: string;
/**
* Whether or not the text field has a leading icon. Used for SSR.
*/
hasLeadingIcon: boolean;
/**
* Whether or not the text field has a trailing icon. Used for SSR.
*/
hasTrailingIcon: boolean;
/**
* Conveys additional information below the text field, such as how it should
* be used.
*/
supportingText: string;
/**
* Override the input text CSS `direction`. Useful for RTL languages that use
* LTR notation for fractions.
*/
textDirection: string;
/**
* The number of rows to display for a `type="textarea"` text field.
* Defaults to 2.
*/
rows: number;
/**
* The associated form element with which this element's value will submit.
*/
get form(): HTMLFormElement;
/**
* The labels this element is associated with.
*/
get labels(): NodeList;
/**
* The HTML name to use in form submission.
*/
get name(): string;
set name(name: string);
inputMode: string;
/**
* Defines the greatest value in the range of permitted values.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#max
*/
max: string;
/**
* The maximum number of characters a user can enter into the text field. Set
* to -1 for none.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#maxlength
*/
maxLength: number;
/**
* Defines the most negative value in the range of permitted values.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#min
*/
min: string;
/**
* The minimum number of characters a user can enter into the text field. Set
* to -1 for none.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#minlength
*/
minLength: number;
/**
* A regular expression that the text field's value must match to pass
* constraint validation.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#pattern
*/
pattern: string;
placeholder: string;
/**
* Indicates whether or not a user should be able to edit the text field's
* value.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#readonly
*/
readOnly: boolean;
/**
* Indicates that input accepts multiple email addresses.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#multiple
*/
multiple: boolean;
/**
* Gets or sets the direction in which selection occurred.
*/
get selectionDirection(): 'forward' | 'backward' | 'none' | null;
set selectionDirection(value: 'forward' | 'backward' | 'none' | null);
/**
* Gets or sets the end position or offset of a text selection.
*/
get selectionEnd(): number | null;
set selectionEnd(value: number | null);
/**
* Gets or sets the starting position or offset of a text selection.
*/
get selectionStart(): number | null;
set selectionStart(value: number | null);
/**
* Returns or sets the element's step attribute, which works with min and max
* to limit the increments at which a numeric or date-time value can be set.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#step
*/
step: string;
/**
* The `<input>` type to use, defaults to "text". The type greatly changes how
* the text field behaves.
*
* Text fields support a limited number of `<input>` types:
*
* - text
* - textarea
* - email
* - number
* - password
* - search
* - tel
* - url
*
* See
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
* for more details on each input type.
*/
type: TextFieldType | UnsupportedTextFieldType;
/**
* Describes what, if any, type of autocomplete functionality the input
* should provide.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
*/
autocomplete: string;
/**
* Returns the text field's validation error message.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
*/
get validationMessage(): string;
/**
* Returns a `ValidityState` object that represents the validity states of the
* text field.
*
* https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
*/
get validity(): ValidityState;
/**
* The text field's value as a number.
*/
get valueAsNumber(): number;
set valueAsNumber(value: number);
/**
* The text field's value as a Date.
*/
get valueAsDate(): Date | null;
set valueAsDate(value: Date | null);
/**
* Returns whether an element will successfully validate based on forms
* validation rules and constraints.
*
* https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate
*/
get willValidate(): boolean;
protected abstract readonly fieldTag: StaticValue;
/**
* Returns true when the text field has been interacted with. Native
* validation errors only display in response to user interactions.
*/
private dirty;
private focused;
/**
* Whether or not a native error has been reported via `reportValidity()`.
*/
private nativeError;
/**
* The validation message displayed from a native error via
* `reportValidity()`.
*/
private nativeErrorText;
private get hasError();
private readonly inputOrTextarea?;
private readonly field?;
private readonly leadingIcons;
private readonly trailingIcons;
private hasCustomValidityError;
private readonly internals;
/**
* Checks the text field's native validation and returns whether or not the
* element is valid.
*
* If invalid, this method will dispatch the `invalid` event.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
*
* @return true if the text field is valid, or false if not.
*/
checkValidity(): boolean;
/**
* Checks the text field's native validation and returns whether or not the
* element is valid.
*
* If invalid, this method will dispatch the `invalid` event.
*
* This method will display or clear an error text message equal to the text
* field's `validationMessage`, unless the invalid event is canceled.
*
* Use `setCustomValidity()` to customize the `validationMessage`.
*
* This method can also be used to re-announce error messages to screen
* readers.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity
*
* @return true if the text field is valid, or false if not.
*/
reportValidity(): boolean;
/**
* Selects all the text in the text field.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select
*/
select(): void;
/**
* Sets a custom validation error message for the text field. Use this for
* custom error message.
*
* When the error is not an empty string, the text field is considered invalid
* and `validity.customError` will be true.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
*
* @param error The error message to display.
*/
setCustomValidity(error: string): void;
/**
* Replaces a range of text with a new string.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setRangeText
*/
setRangeText(replacement: string): void;
setRangeText(replacement: string, start: number, end: number, selectionMode?: SelectionMode): void;
/**
* Sets the start and end positions of a selection in the text field.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
*
* @param start The offset into the text field for the start of the selection.
* @param end The offset into the text field for the end of the selection.
* @param direction The direction in which the selection is performed.
*/
setSelectionRange(start: number | null, end: number | null, direction?: 'forward' | 'backward' | 'none'): void;
/**
* Decrements the value of a numeric type text field by `step` or `n` `step`
* number of times.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepDown
*
* @param stepDecrement The number of steps to decrement, defaults to 1.
*/
stepDown(stepDecrement?: number): void;
/**
* Increments the value of a numeric type text field by `step` or `n` `step`
* number of times.
*
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepUp
*
* @param stepIncrement The number of steps to increment, defaults to 1.
*/
stepUp(stepIncrement?: number): void;
/**
* Reset the text field to its default value.
*/
reset(): void;
attributeChangedCallback(attribute: string, newValue: string | null, oldValue: string | null): void;
protected render(): import("lit-html").TemplateResult<1>;
protected updated(changedProperties: PropertyValues): void;
private renderField;
private renderLeadingIcon;
private renderTrailingIcon;
private renderInputOrTextarea;
private renderPrefix;
private renderSuffix;
private renderAffix;
private getErrorText;
private handleFocusin;
private handleFocusout;
private handleInput;
private handleChange;
private redispatchEvent;
private getInputOrTextarea;
private getInput;
private syncValidity;
private handleIconChange;
/** @private */
formResetCallback(): void;
/** @private */
formStateRestoreCallback(state: string): void;
focus(): void;
}