input.es5.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { __extends } from 'tslib';
  9. import { CdkTextareaAutosize, AutofillMonitor, TextFieldModule } from '@angular/cdk/text-field';
  10. import { Directive, Input, InjectionToken, ElementRef, Inject, NgZone, Optional, Self, NgModule } from '@angular/core';
  11. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  12. import { getSupportedInputTypes, Platform } from '@angular/cdk/platform';
  13. import { FormGroupDirective, NgControl, NgForm } from '@angular/forms';
  14. import { ErrorStateMatcher, mixinErrorState } from '@angular/material/core';
  15. import { MatFormFieldControl, MatFormFieldModule } from '@angular/material/form-field';
  16. import { Subject } from 'rxjs';
  17. import { CommonModule } from '@angular/common';
  18. /**
  19. * @fileoverview added by tsickle
  20. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  21. */
  22. /**
  23. * Directive to automatically resize a textarea to fit its content.
  24. * @deprecated Use `cdkTextareaAutosize` from `\@angular/cdk/text-field` instead.
  25. * \@breaking-change 8.0.0
  26. */
  27. var MatTextareaAutosize = /** @class */ (function (_super) {
  28. __extends(MatTextareaAutosize, _super);
  29. function MatTextareaAutosize() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. Object.defineProperty(MatTextareaAutosize.prototype, "matAutosizeMinRows", {
  33. get: /**
  34. * @return {?}
  35. */
  36. function () { return this.minRows; },
  37. set: /**
  38. * @param {?} value
  39. * @return {?}
  40. */
  41. function (value) { this.minRows = value; },
  42. enumerable: true,
  43. configurable: true
  44. });
  45. Object.defineProperty(MatTextareaAutosize.prototype, "matAutosizeMaxRows", {
  46. get: /**
  47. * @return {?}
  48. */
  49. function () { return this.maxRows; },
  50. set: /**
  51. * @param {?} value
  52. * @return {?}
  53. */
  54. function (value) { this.maxRows = value; },
  55. enumerable: true,
  56. configurable: true
  57. });
  58. Object.defineProperty(MatTextareaAutosize.prototype, "matAutosize", {
  59. get: /**
  60. * @return {?}
  61. */
  62. function () { return this.enabled; },
  63. set: /**
  64. * @param {?} value
  65. * @return {?}
  66. */
  67. function (value) { this.enabled = value; },
  68. enumerable: true,
  69. configurable: true
  70. });
  71. Object.defineProperty(MatTextareaAutosize.prototype, "matTextareaAutosize", {
  72. get: /**
  73. * @return {?}
  74. */
  75. function () { return this.enabled; },
  76. set: /**
  77. * @param {?} value
  78. * @return {?}
  79. */
  80. function (value) { this.enabled = value; },
  81. enumerable: true,
  82. configurable: true
  83. });
  84. MatTextareaAutosize.decorators = [
  85. { type: Directive, args: [{
  86. selector: 'textarea[mat-autosize], textarea[matTextareaAutosize]',
  87. exportAs: 'matTextareaAutosize',
  88. inputs: ['cdkAutosizeMinRows', 'cdkAutosizeMaxRows'],
  89. host: {
  90. 'class': 'cdk-textarea-autosize mat-autosize',
  91. // Textarea elements that have the directive applied should have a single row by default.
  92. // Browsers normally show two rows by default and therefore this limits the minRows binding.
  93. 'rows': '1',
  94. '(input)': '_noopInputHandler()',
  95. },
  96. },] },
  97. ];
  98. MatTextareaAutosize.propDecorators = {
  99. matAutosizeMinRows: [{ type: Input }],
  100. matAutosizeMaxRows: [{ type: Input }],
  101. matAutosize: [{ type: Input, args: ['mat-autosize',] }],
  102. matTextareaAutosize: [{ type: Input }]
  103. };
  104. return MatTextareaAutosize;
  105. }(CdkTextareaAutosize));
  106. /**
  107. * @fileoverview added by tsickle
  108. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  109. */
  110. /**
  111. * \@docs-private
  112. * @param {?} type
  113. * @return {?}
  114. */
  115. function getMatInputUnsupportedTypeError(type) {
  116. return Error("Input type \"" + type + "\" isn't supported by matInput.");
  117. }
  118. /**
  119. * @fileoverview added by tsickle
  120. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  121. */
  122. /**
  123. * This token is used to inject the object whose value should be set into `MatInput`. If none is
  124. * provided, the native `HTMLInputElement` is used. Directives like `MatDatepickerInput` can provide
  125. * themselves for this token, in order to make `MatInput` delegate the getting and setting of the
  126. * value to them.
  127. * @type {?}
  128. */
  129. var MAT_INPUT_VALUE_ACCESSOR = new InjectionToken('MAT_INPUT_VALUE_ACCESSOR');
  130. /**
  131. * @fileoverview added by tsickle
  132. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  133. */
  134. // Invalid input type. Using one of these will throw an MatInputUnsupportedTypeError.
  135. /** @type {?} */
  136. var MAT_INPUT_INVALID_TYPES = [
  137. 'button',
  138. 'checkbox',
  139. 'file',
  140. 'hidden',
  141. 'image',
  142. 'radio',
  143. 'range',
  144. 'reset',
  145. 'submit'
  146. ];
  147. /** @type {?} */
  148. var nextUniqueId = 0;
  149. // Boilerplate for applying mixins to MatInput.
  150. /**
  151. * \@docs-private
  152. */
  153. var
  154. // Boilerplate for applying mixins to MatInput.
  155. /**
  156. * \@docs-private
  157. */
  158. MatInputBase = /** @class */ (function () {
  159. function MatInputBase(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) {
  160. this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
  161. this._parentForm = _parentForm;
  162. this._parentFormGroup = _parentFormGroup;
  163. this.ngControl = ngControl;
  164. }
  165. return MatInputBase;
  166. }());
  167. /** @type {?} */
  168. var _MatInputMixinBase = mixinErrorState(MatInputBase);
  169. /**
  170. * Directive that allows a native input to work inside a `MatFormField`.
  171. */
  172. var MatInput = /** @class */ (function (_super) {
  173. __extends(MatInput, _super);
  174. function MatInput(_elementRef, _platform, ngControl, _parentForm, _parentFormGroup, _defaultErrorStateMatcher, inputValueAccessor, _autofillMonitor, ngZone) {
  175. var _this = _super.call(this, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) || this;
  176. _this._elementRef = _elementRef;
  177. _this._platform = _platform;
  178. _this.ngControl = ngControl;
  179. _this._autofillMonitor = _autofillMonitor;
  180. _this._uid = "mat-input-" + nextUniqueId++;
  181. /**
  182. * Whether the component is being rendered on the server.
  183. */
  184. _this._isServer = false;
  185. /**
  186. * Whether the component is a native html select.
  187. */
  188. _this._isNativeSelect = false;
  189. /**
  190. * Implemented as part of MatFormFieldControl.
  191. * \@docs-private
  192. */
  193. _this.focused = false;
  194. /**
  195. * Implemented as part of MatFormFieldControl.
  196. * \@docs-private
  197. */
  198. _this.stateChanges = new Subject();
  199. /**
  200. * Implemented as part of MatFormFieldControl.
  201. * \@docs-private
  202. */
  203. _this.controlType = 'mat-input';
  204. /**
  205. * Implemented as part of MatFormFieldControl.
  206. * \@docs-private
  207. */
  208. _this.autofilled = false;
  209. _this._disabled = false;
  210. _this._required = false;
  211. _this._type = 'text';
  212. _this._readonly = false;
  213. _this._neverEmptyInputTypes = [
  214. 'date',
  215. 'datetime',
  216. 'datetime-local',
  217. 'month',
  218. 'time',
  219. 'week'
  220. ].filter((/**
  221. * @param {?} t
  222. * @return {?}
  223. */
  224. function (t) { return getSupportedInputTypes().has(t); }));
  225. /** @type {?} */
  226. var element = _this._elementRef.nativeElement;
  227. // If no input value accessor was explicitly specified, use the element as the input value
  228. // accessor.
  229. _this._inputValueAccessor = inputValueAccessor || element;
  230. _this._previousNativeValue = _this.value;
  231. // Force setter to be called in case id was not specified.
  232. _this.id = _this.id;
  233. // On some versions of iOS the caret gets stuck in the wrong place when holding down the delete
  234. // key. In order to get around this we need to "jiggle" the caret loose. Since this bug only
  235. // exists on iOS, we only bother to install the listener on iOS.
  236. if (_platform.IOS) {
  237. ngZone.runOutsideAngular((/**
  238. * @return {?}
  239. */
  240. function () {
  241. _elementRef.nativeElement.addEventListener('keyup', (/**
  242. * @param {?} event
  243. * @return {?}
  244. */
  245. function (event) {
  246. /** @type {?} */
  247. var el = (/** @type {?} */ (event.target));
  248. if (!el.value && !el.selectionStart && !el.selectionEnd) {
  249. // Note: Just setting `0, 0` doesn't fix the issue. Setting
  250. // `1, 1` fixes it for the first time that you type text and
  251. // then hold delete. Toggling to `1, 1` and then back to
  252. // `0, 0` seems to completely fix it.
  253. el.setSelectionRange(1, 1);
  254. el.setSelectionRange(0, 0);
  255. }
  256. }));
  257. }));
  258. }
  259. _this._isServer = !_this._platform.isBrowser;
  260. _this._isNativeSelect = element.nodeName.toLowerCase() === 'select';
  261. if (_this._isNativeSelect) {
  262. _this.controlType = ((/** @type {?} */ (element))).multiple ? 'mat-native-select-multiple' :
  263. 'mat-native-select';
  264. }
  265. return _this;
  266. }
  267. Object.defineProperty(MatInput.prototype, "disabled", {
  268. /**
  269. * Implemented as part of MatFormFieldControl.
  270. * @docs-private
  271. */
  272. get: /**
  273. * Implemented as part of MatFormFieldControl.
  274. * \@docs-private
  275. * @return {?}
  276. */
  277. function () {
  278. if (this.ngControl && this.ngControl.disabled !== null) {
  279. return this.ngControl.disabled;
  280. }
  281. return this._disabled;
  282. },
  283. set: /**
  284. * @param {?} value
  285. * @return {?}
  286. */
  287. function (value) {
  288. this._disabled = coerceBooleanProperty(value);
  289. // Browsers may not fire the blur event if the input is disabled too quickly.
  290. // Reset from here to ensure that the element doesn't become stuck.
  291. if (this.focused) {
  292. this.focused = false;
  293. this.stateChanges.next();
  294. }
  295. },
  296. enumerable: true,
  297. configurable: true
  298. });
  299. Object.defineProperty(MatInput.prototype, "id", {
  300. /**
  301. * Implemented as part of MatFormFieldControl.
  302. * @docs-private
  303. */
  304. get: /**
  305. * Implemented as part of MatFormFieldControl.
  306. * \@docs-private
  307. * @return {?}
  308. */
  309. function () { return this._id; },
  310. set: /**
  311. * @param {?} value
  312. * @return {?}
  313. */
  314. function (value) { this._id = value || this._uid; },
  315. enumerable: true,
  316. configurable: true
  317. });
  318. Object.defineProperty(MatInput.prototype, "required", {
  319. /**
  320. * Implemented as part of MatFormFieldControl.
  321. * @docs-private
  322. */
  323. get: /**
  324. * Implemented as part of MatFormFieldControl.
  325. * \@docs-private
  326. * @return {?}
  327. */
  328. function () { return this._required; },
  329. set: /**
  330. * @param {?} value
  331. * @return {?}
  332. */
  333. function (value) { this._required = coerceBooleanProperty(value); },
  334. enumerable: true,
  335. configurable: true
  336. });
  337. Object.defineProperty(MatInput.prototype, "type", {
  338. /** Input type of the element. */
  339. get: /**
  340. * Input type of the element.
  341. * @return {?}
  342. */
  343. function () { return this._type; },
  344. set: /**
  345. * @param {?} value
  346. * @return {?}
  347. */
  348. function (value) {
  349. this._type = value || 'text';
  350. this._validateType();
  351. // When using Angular inputs, developers are no longer able to set the properties on the native
  352. // input element. To ensure that bindings for `type` work, we need to sync the setter
  353. // with the native property. Textarea elements don't support the type property or attribute.
  354. if (!this._isTextarea() && getSupportedInputTypes().has(this._type)) {
  355. ((/** @type {?} */ (this._elementRef.nativeElement))).type = this._type;
  356. }
  357. },
  358. enumerable: true,
  359. configurable: true
  360. });
  361. Object.defineProperty(MatInput.prototype, "value", {
  362. /**
  363. * Implemented as part of MatFormFieldControl.
  364. * @docs-private
  365. */
  366. get: /**
  367. * Implemented as part of MatFormFieldControl.
  368. * \@docs-private
  369. * @return {?}
  370. */
  371. function () { return this._inputValueAccessor.value; },
  372. set: /**
  373. * @param {?} value
  374. * @return {?}
  375. */
  376. function (value) {
  377. if (value !== this.value) {
  378. this._inputValueAccessor.value = value;
  379. this.stateChanges.next();
  380. }
  381. },
  382. enumerable: true,
  383. configurable: true
  384. });
  385. Object.defineProperty(MatInput.prototype, "readonly", {
  386. /** Whether the element is readonly. */
  387. get: /**
  388. * Whether the element is readonly.
  389. * @return {?}
  390. */
  391. function () { return this._readonly; },
  392. set: /**
  393. * @param {?} value
  394. * @return {?}
  395. */
  396. function (value) { this._readonly = coerceBooleanProperty(value); },
  397. enumerable: true,
  398. configurable: true
  399. });
  400. /**
  401. * @return {?}
  402. */
  403. MatInput.prototype.ngOnInit = /**
  404. * @return {?}
  405. */
  406. function () {
  407. var _this = this;
  408. if (this._platform.isBrowser) {
  409. this._autofillMonitor.monitor(this._elementRef.nativeElement).subscribe((/**
  410. * @param {?} event
  411. * @return {?}
  412. */
  413. function (event) {
  414. _this.autofilled = event.isAutofilled;
  415. _this.stateChanges.next();
  416. }));
  417. }
  418. };
  419. /**
  420. * @return {?}
  421. */
  422. MatInput.prototype.ngOnChanges = /**
  423. * @return {?}
  424. */
  425. function () {
  426. this.stateChanges.next();
  427. };
  428. /**
  429. * @return {?}
  430. */
  431. MatInput.prototype.ngOnDestroy = /**
  432. * @return {?}
  433. */
  434. function () {
  435. this.stateChanges.complete();
  436. if (this._platform.isBrowser) {
  437. this._autofillMonitor.stopMonitoring(this._elementRef.nativeElement);
  438. }
  439. };
  440. /**
  441. * @return {?}
  442. */
  443. MatInput.prototype.ngDoCheck = /**
  444. * @return {?}
  445. */
  446. function () {
  447. if (this.ngControl) {
  448. // We need to re-evaluate this on every change detection cycle, because there are some
  449. // error triggers that we can't subscribe to (e.g. parent form submissions). This means
  450. // that whatever logic is in here has to be super lean or we risk destroying the performance.
  451. this.updateErrorState();
  452. }
  453. // We need to dirty-check the native element's value, because there are some cases where
  454. // we won't be notified when it changes (e.g. the consumer isn't using forms or they're
  455. // updating the value using `emitEvent: false`).
  456. this._dirtyCheckNativeValue();
  457. };
  458. /** Focuses the input. */
  459. /**
  460. * Focuses the input.
  461. * @param {?=} options
  462. * @return {?}
  463. */
  464. MatInput.prototype.focus = /**
  465. * Focuses the input.
  466. * @param {?=} options
  467. * @return {?}
  468. */
  469. function (options) {
  470. this._elementRef.nativeElement.focus(options);
  471. };
  472. /** Callback for the cases where the focused state of the input changes. */
  473. /**
  474. * Callback for the cases where the focused state of the input changes.
  475. * @param {?} isFocused
  476. * @return {?}
  477. */
  478. MatInput.prototype._focusChanged = /**
  479. * Callback for the cases where the focused state of the input changes.
  480. * @param {?} isFocused
  481. * @return {?}
  482. */
  483. function (isFocused) {
  484. if (isFocused !== this.focused && (!this.readonly || !isFocused)) {
  485. this.focused = isFocused;
  486. this.stateChanges.next();
  487. }
  488. };
  489. /**
  490. * @return {?}
  491. */
  492. MatInput.prototype._onInput = /**
  493. * @return {?}
  494. */
  495. function () {
  496. // This is a noop function and is used to let Angular know whenever the value changes.
  497. // Angular will run a new change detection each time the `input` event has been dispatched.
  498. // It's necessary that Angular recognizes the value change, because when floatingLabel
  499. // is set to false and Angular forms aren't used, the placeholder won't recognize the
  500. // value changes and will not disappear.
  501. // Listening to the input event wouldn't be necessary when the input is using the
  502. // FormsModule or ReactiveFormsModule, because Angular forms also listens to input events.
  503. };
  504. /** Does some manual dirty checking on the native input `value` property. */
  505. /**
  506. * Does some manual dirty checking on the native input `value` property.
  507. * @protected
  508. * @return {?}
  509. */
  510. MatInput.prototype._dirtyCheckNativeValue = /**
  511. * Does some manual dirty checking on the native input `value` property.
  512. * @protected
  513. * @return {?}
  514. */
  515. function () {
  516. /** @type {?} */
  517. var newValue = this._elementRef.nativeElement.value;
  518. if (this._previousNativeValue !== newValue) {
  519. this._previousNativeValue = newValue;
  520. this.stateChanges.next();
  521. }
  522. };
  523. /** Make sure the input is a supported type. */
  524. /**
  525. * Make sure the input is a supported type.
  526. * @protected
  527. * @return {?}
  528. */
  529. MatInput.prototype._validateType = /**
  530. * Make sure the input is a supported type.
  531. * @protected
  532. * @return {?}
  533. */
  534. function () {
  535. if (MAT_INPUT_INVALID_TYPES.indexOf(this._type) > -1) {
  536. throw getMatInputUnsupportedTypeError(this._type);
  537. }
  538. };
  539. /** Checks whether the input type is one of the types that are never empty. */
  540. /**
  541. * Checks whether the input type is one of the types that are never empty.
  542. * @protected
  543. * @return {?}
  544. */
  545. MatInput.prototype._isNeverEmpty = /**
  546. * Checks whether the input type is one of the types that are never empty.
  547. * @protected
  548. * @return {?}
  549. */
  550. function () {
  551. return this._neverEmptyInputTypes.indexOf(this._type) > -1;
  552. };
  553. /** Checks whether the input is invalid based on the native validation. */
  554. /**
  555. * Checks whether the input is invalid based on the native validation.
  556. * @protected
  557. * @return {?}
  558. */
  559. MatInput.prototype._isBadInput = /**
  560. * Checks whether the input is invalid based on the native validation.
  561. * @protected
  562. * @return {?}
  563. */
  564. function () {
  565. // The `validity` property won't be present on platform-server.
  566. /** @type {?} */
  567. var validity = ((/** @type {?} */ (this._elementRef.nativeElement))).validity;
  568. return validity && validity.badInput;
  569. };
  570. /** Determines if the component host is a textarea. */
  571. /**
  572. * Determines if the component host is a textarea.
  573. * @protected
  574. * @return {?}
  575. */
  576. MatInput.prototype._isTextarea = /**
  577. * Determines if the component host is a textarea.
  578. * @protected
  579. * @return {?}
  580. */
  581. function () {
  582. return this._elementRef.nativeElement.nodeName.toLowerCase() === 'textarea';
  583. };
  584. Object.defineProperty(MatInput.prototype, "empty", {
  585. /**
  586. * Implemented as part of MatFormFieldControl.
  587. * @docs-private
  588. */
  589. get: /**
  590. * Implemented as part of MatFormFieldControl.
  591. * \@docs-private
  592. * @return {?}
  593. */
  594. function () {
  595. return !this._isNeverEmpty() && !this._elementRef.nativeElement.value && !this._isBadInput() &&
  596. !this.autofilled;
  597. },
  598. enumerable: true,
  599. configurable: true
  600. });
  601. Object.defineProperty(MatInput.prototype, "shouldLabelFloat", {
  602. /**
  603. * Implemented as part of MatFormFieldControl.
  604. * @docs-private
  605. */
  606. get: /**
  607. * Implemented as part of MatFormFieldControl.
  608. * \@docs-private
  609. * @return {?}
  610. */
  611. function () {
  612. if (this._isNativeSelect) {
  613. // For a single-selection `<select>`, the label should float when the selected option has
  614. // a non-empty display value. For a `<select multiple>`, the label *always* floats to avoid
  615. // overlapping the label with the options.
  616. /** @type {?} */
  617. var selectElement = (/** @type {?} */ (this._elementRef.nativeElement));
  618. /** @type {?} */
  619. var firstOption = selectElement.options[0];
  620. // On most browsers the `selectedIndex` will always be 0, however on IE and Edge it'll be
  621. // -1 if the `value` is set to something, that isn't in the list of options, at a later point.
  622. return this.focused || selectElement.multiple || !this.empty ||
  623. !!(selectElement.selectedIndex > -1 && firstOption && firstOption.label);
  624. }
  625. else {
  626. return this.focused || !this.empty;
  627. }
  628. },
  629. enumerable: true,
  630. configurable: true
  631. });
  632. /**
  633. * Implemented as part of MatFormFieldControl.
  634. * @docs-private
  635. */
  636. /**
  637. * Implemented as part of MatFormFieldControl.
  638. * \@docs-private
  639. * @param {?} ids
  640. * @return {?}
  641. */
  642. MatInput.prototype.setDescribedByIds = /**
  643. * Implemented as part of MatFormFieldControl.
  644. * \@docs-private
  645. * @param {?} ids
  646. * @return {?}
  647. */
  648. function (ids) {
  649. this._ariaDescribedby = ids.join(' ');
  650. };
  651. /**
  652. * Implemented as part of MatFormFieldControl.
  653. * @docs-private
  654. */
  655. /**
  656. * Implemented as part of MatFormFieldControl.
  657. * \@docs-private
  658. * @return {?}
  659. */
  660. MatInput.prototype.onContainerClick = /**
  661. * Implemented as part of MatFormFieldControl.
  662. * \@docs-private
  663. * @return {?}
  664. */
  665. function () {
  666. // Do not re-focus the input element if the element is already focused. Otherwise it can happen
  667. // that someone clicks on a time input and the cursor resets to the "hours" field while the
  668. // "minutes" field was actually clicked. See: https://github.com/angular/components/issues/12849
  669. if (!this.focused) {
  670. this.focus();
  671. }
  672. };
  673. MatInput.decorators = [
  674. { type: Directive, args: [{
  675. selector: "input[matInput], textarea[matInput], select[matNativeControl],\n input[matNativeControl], textarea[matNativeControl]",
  676. exportAs: 'matInput',
  677. host: {
  678. /**
  679. * \@breaking-change 8.0.0 remove .mat-form-field-autofill-control in favor of AutofillMonitor.
  680. */
  681. 'class': 'mat-input-element mat-form-field-autofill-control',
  682. '[class.mat-input-server]': '_isServer',
  683. // Native input properties that are overwritten by Angular inputs need to be synced with
  684. // the native input element. Otherwise property bindings for those don't work.
  685. '[attr.id]': 'id',
  686. '[attr.placeholder]': 'placeholder',
  687. '[disabled]': 'disabled',
  688. '[required]': 'required',
  689. '[attr.readonly]': 'readonly && !_isNativeSelect || null',
  690. '[attr.aria-describedby]': '_ariaDescribedby || null',
  691. '[attr.aria-invalid]': 'errorState',
  692. '[attr.aria-required]': 'required.toString()',
  693. '(blur)': '_focusChanged(false)',
  694. '(focus)': '_focusChanged(true)',
  695. '(input)': '_onInput()',
  696. },
  697. providers: [{ provide: MatFormFieldControl, useExisting: MatInput }],
  698. },] },
  699. ];
  700. /** @nocollapse */
  701. MatInput.ctorParameters = function () { return [
  702. { type: ElementRef },
  703. { type: Platform },
  704. { type: NgControl, decorators: [{ type: Optional }, { type: Self }] },
  705. { type: NgForm, decorators: [{ type: Optional }] },
  706. { type: FormGroupDirective, decorators: [{ type: Optional }] },
  707. { type: ErrorStateMatcher },
  708. { type: undefined, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [MAT_INPUT_VALUE_ACCESSOR,] }] },
  709. { type: AutofillMonitor },
  710. { type: NgZone }
  711. ]; };
  712. MatInput.propDecorators = {
  713. disabled: [{ type: Input }],
  714. id: [{ type: Input }],
  715. placeholder: [{ type: Input }],
  716. required: [{ type: Input }],
  717. type: [{ type: Input }],
  718. errorStateMatcher: [{ type: Input }],
  719. value: [{ type: Input }],
  720. readonly: [{ type: Input }]
  721. };
  722. return MatInput;
  723. }(_MatInputMixinBase));
  724. /**
  725. * @fileoverview added by tsickle
  726. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  727. */
  728. var MatInputModule = /** @class */ (function () {
  729. function MatInputModule() {
  730. }
  731. MatInputModule.decorators = [
  732. { type: NgModule, args: [{
  733. declarations: [MatInput, MatTextareaAutosize],
  734. imports: [
  735. CommonModule,
  736. TextFieldModule,
  737. MatFormFieldModule,
  738. ],
  739. exports: [
  740. TextFieldModule,
  741. // We re-export the `MatFormFieldModule` since `MatInput` will almost always
  742. // be used together with `MatFormField`.
  743. MatFormFieldModule,
  744. MatInput,
  745. MatTextareaAutosize,
  746. ],
  747. providers: [ErrorStateMatcher],
  748. },] },
  749. ];
  750. return MatInputModule;
  751. }());
  752. /**
  753. * @fileoverview added by tsickle
  754. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  755. */
  756. /**
  757. * @fileoverview added by tsickle
  758. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  759. */
  760. export { MatTextareaAutosize, MatInput, getMatInputUnsupportedTypeError, MatInputModule, MAT_INPUT_VALUE_ACCESSOR };
  761. //# sourceMappingURL=input.es5.js.map