foundation.d.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. import { MDCFoundation } from '@material/base/foundation';
  24. import { MDCTextFieldAdapter } from './adapter';
  25. import { MDCTextFieldFoundationMap } from './types';
  26. /** MDC Text Field Foundation */
  27. export declare class MDCTextFieldFoundation extends MDCFoundation<MDCTextFieldAdapter> {
  28. static get cssClasses(): {
  29. DISABLED: string;
  30. FOCUSED: string;
  31. HELPER_LINE: string;
  32. INVALID: string;
  33. LABEL_FLOATING: string;
  34. NO_LABEL: string;
  35. OUTLINED: string;
  36. ROOT: string;
  37. /** MDC Text Field Foundation */
  38. TEXTAREA: string;
  39. WITH_LEADING_ICON: string;
  40. WITH_TRAILING_ICON: string;
  41. WITH_INTERNAL_COUNTER: string;
  42. };
  43. static get strings(): {
  44. ARIA_CONTROLS: string;
  45. ARIA_DESCRIBEDBY: string;
  46. INPUT_SELECTOR: string;
  47. LABEL_SELECTOR: string;
  48. LEADING_ICON_SELECTOR: string;
  49. LINE_RIPPLE_SELECTOR: string;
  50. OUTLINE_SELECTOR: string;
  51. PREFIX_SELECTOR: string;
  52. SUFFIX_SELECTOR: string;
  53. TRAILING_ICON_SELECTOR: string;
  54. };
  55. static get numbers(): {
  56. LABEL_SCALE: number;
  57. };
  58. private get shouldAlwaysFloat();
  59. get shouldFloat(): boolean;
  60. get shouldShake(): boolean;
  61. /**
  62. * See {@link MDCTextFieldAdapter} for typing information on parameters and
  63. * return types.
  64. */
  65. static get defaultAdapter(): MDCTextFieldAdapter;
  66. private isFocused;
  67. private receivedUserInput;
  68. private useNativeValidation;
  69. private validateOnValueChange;
  70. private valid;
  71. private readonly inputFocusHandler;
  72. private readonly inputBlurHandler;
  73. private readonly inputInputHandler;
  74. private readonly setPointerXOffset;
  75. private readonly textFieldInteractionHandler;
  76. private readonly validationAttributeChangeHandler;
  77. private validationObserver;
  78. private readonly helperText?;
  79. private readonly characterCounter?;
  80. private readonly leadingIcon?;
  81. private readonly trailingIcon?;
  82. /**
  83. * @param adapter
  84. * @param foundationMap Map from subcomponent names to their subfoundations.
  85. */
  86. constructor(adapter?: Partial<MDCTextFieldAdapter>, foundationMap?: Partial<MDCTextFieldFoundationMap>);
  87. init(): void;
  88. destroy(): void;
  89. /**
  90. * Handles user interactions with the Text Field.
  91. */
  92. handleTextFieldInteraction(): void;
  93. /**
  94. * Handles validation attribute changes
  95. */
  96. handleValidationAttributeChange(attributesList: string[]): void;
  97. /**
  98. * Opens/closes the notched outline.
  99. */
  100. notchOutline(openNotch: boolean): void;
  101. /**
  102. * Activates the text field focus state.
  103. */
  104. activateFocus(): void;
  105. /**
  106. * Sets the line ripple's transform origin, so that the line ripple activate
  107. * animation will animate out from the user's click location.
  108. */
  109. setTransformOrigin(evt: TouchEvent | MouseEvent): void;
  110. /**
  111. * Handles input change of text input and text area.
  112. */
  113. handleInput(): void;
  114. /**
  115. * Activates the Text Field's focus state in cases when the input value
  116. * changes without user input (e.g. programmatically).
  117. */
  118. autoCompleteFocus(): void;
  119. /**
  120. * Deactivates the Text Field's focus state.
  121. */
  122. deactivateFocus(): void;
  123. getValue(): string;
  124. /**
  125. * @param value The value to set on the input Element.
  126. */
  127. setValue(value: string): void;
  128. /**
  129. * @return The custom validity state, if set; otherwise, the result of a
  130. * native validity check.
  131. */
  132. isValid(): boolean;
  133. /**
  134. * @param isValid Sets the custom validity state of the Text Field.
  135. */
  136. setValid(isValid: boolean): void;
  137. /**
  138. * @param shouldValidate Whether or not validity should be updated on
  139. * value change.
  140. */
  141. setValidateOnValueChange(shouldValidate: boolean): void;
  142. /**
  143. * @return Whether or not validity should be updated on value change. `true`
  144. * by default.
  145. */
  146. getValidateOnValueChange(): boolean;
  147. /**
  148. * Enables or disables the use of native validation. Use this for custom
  149. * validation.
  150. * @param useNativeValidation Set this to false to ignore native input
  151. * validation.
  152. */
  153. setUseNativeValidation(useNativeValidation: boolean): void;
  154. isDisabled(): boolean;
  155. /**
  156. * @param disabled Sets the text-field disabled or enabled.
  157. */
  158. setDisabled(disabled: boolean): void;
  159. /**
  160. * @param content Sets the content of the helper text.
  161. */
  162. setHelperTextContent(content: string): void;
  163. /**
  164. * Sets the aria label of the leading icon.
  165. */
  166. setLeadingIconAriaLabel(label: string): void;
  167. /**
  168. * Sets the text content of the leading icon.
  169. */
  170. setLeadingIconContent(content: string): void;
  171. /**
  172. * Sets the aria label of the trailing icon.
  173. */
  174. setTrailingIconAriaLabel(label: string): void;
  175. /**
  176. * Sets the text content of the trailing icon.
  177. */
  178. setTrailingIconContent(content: string): void;
  179. /**
  180. * Sets character counter values that shows characters used and the total
  181. * character limit.
  182. */
  183. private setcharacterCounter;
  184. /**
  185. * @return True if the Text Field input fails in converting the user-supplied
  186. * value.
  187. */
  188. private isBadInput;
  189. /**
  190. * @return The result of native validity checking (ValidityState.valid).
  191. */
  192. private isNativeInputValid;
  193. /**
  194. * Styles the component based on the validity state.
  195. */
  196. private styleValidity;
  197. /**
  198. * Styles the component based on the focused state.
  199. */
  200. private styleFocused;
  201. /**
  202. * Styles the component based on the disabled state.
  203. */
  204. private styleDisabled;
  205. /**
  206. * Styles the component based on the label floating state.
  207. */
  208. private styleFloating;
  209. /**
  210. * @return The native text input element from the host environment, or an
  211. * object with the same shape for unit tests.
  212. */
  213. private getNativeInput;
  214. }
  215. export default MDCTextFieldFoundation;