123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "@angular/core", "@angular/forms", "rxjs/Subject", "rxjs/add/operator/takeUntil", "../app/app", "../../config/config", "../content/content", "../../util/dom", "../../platform/dom-controller", "../../util/form", "../../util/base-input", "../../util/util", "../item/item", "../../platform/platform"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var core_1 = require("@angular/core");
  23. var forms_1 = require("@angular/forms");
  24. var Subject_1 = require("rxjs/Subject");
  25. require("rxjs/add/operator/takeUntil");
  26. var app_1 = require("../app/app");
  27. var config_1 = require("../../config/config");
  28. var content_1 = require("../content/content");
  29. var dom_1 = require("../../util/dom");
  30. var dom_controller_1 = require("../../platform/dom-controller");
  31. var form_1 = require("../../util/form");
  32. var base_input_1 = require("../../util/base-input");
  33. var util_1 = require("../../util/util");
  34. var item_1 = require("../item/item");
  35. var platform_1 = require("../../platform/platform");
  36. /**
  37. * @name Input
  38. * @description
  39. *
  40. * `ion-input` is meant for text type inputs only, such as `text`,
  41. * `password`, `email`, `number`, `search`, `tel`, and `url`. Ionic
  42. * still uses an actual `<input type="text">` HTML element within the
  43. * component, however, with Ionic wrapping the native HTML input
  44. * element it's better able to handle the user experience and
  45. * interactivity.
  46. *
  47. * Similarly, `<ion-textarea>` should be used in place of `<textarea>`.
  48. *
  49. * An `ion-input` is **not** used for non-text type inputs, such as a
  50. * `checkbox`, `radio`, `toggle`, `range`, `select`, etc.
  51. *
  52. * Along with the blur/focus events, `input` support all standard text input
  53. * events like `keyup`, `keydown`, `keypress`, `input`,etc. Any standard event
  54. * can be attached and will function as expected.
  55. *
  56. * @usage
  57. * ```html
  58. * <ion-list>
  59. * <ion-item>
  60. * <ion-label color="primary">Inline Label</ion-label>
  61. * <ion-input placeholder="Text Input"></ion-input>
  62. * </ion-item>
  63. *
  64. * <ion-item>
  65. * <ion-label color="primary" fixed>Fixed Label</ion-label>
  66. * <ion-input type="tel" placeholder="Tel Input"></ion-input>
  67. * </ion-item>
  68. *
  69. * <ion-item>
  70. * <ion-input type="number" placeholder="Number Input with no label"></ion-input>
  71. * </ion-item>
  72. *
  73. * <ion-item>
  74. * <ion-label color="primary" stacked>Stacked Label</ion-label>
  75. * <ion-input type="email" placeholder="Email Input"></ion-input>
  76. * </ion-item>
  77. *
  78. * <ion-item>
  79. * <ion-label color="primary" stacked>Stacked Label</ion-label>
  80. * <ion-input type="password" placeholder="Password Input"></ion-input>
  81. * </ion-item>
  82. *
  83. * <ion-item>
  84. * <ion-label color="primary" floating>Floating Label</ion-label>
  85. * <ion-input></ion-input>
  86. * </ion-item>
  87. *
  88. * <ion-item>
  89. * <ion-input placeholder="Clear Input" clearInput></ion-input>
  90. * </ion-item>
  91. *
  92. * <ion-item>
  93. * <ion-textarea placeholder="Enter a description"></ion-textarea>
  94. * </ion-item>
  95. * </ion-list>
  96. * ```
  97. *
  98. * @demo /docs/demos/src/input/
  99. */
  100. var TextInput = (function (_super) {
  101. __extends(TextInput, _super);
  102. function TextInput(config, _plt, _form, _app, elementRef, renderer, _content, _item, ngControl, _dom) {
  103. var _this = _super.call(this, config, elementRef, renderer, 'input', '', _form, _item, ngControl) || this;
  104. _this._plt = _plt;
  105. _this._app = _app;
  106. _this._content = _content;
  107. _this.ngControl = ngControl;
  108. _this._dom = _dom;
  109. _this._clearInput = false;
  110. _this._readonly = false;
  111. _this._type = 'text';
  112. _this._isTextarea = false;
  113. _this._onDestroy = new Subject_1.Subject();
  114. _this._useAssist = false;
  115. _this._relocated = false;
  116. /**
  117. * @input {string} Set the input's autocomplete property. Values: `"on"`, `"off"`. Default `"off"`.
  118. */
  119. _this.autocomplete = '';
  120. /**
  121. * @input {string} Set the input's autocorrect property. Values: `"on"`, `"off"`. Default `"off"`.
  122. */
  123. _this.autocorrect = '';
  124. /**
  125. * @input {string} Instructional text that shows before the input has a value.
  126. */
  127. _this.placeholder = '';
  128. /**
  129. * @input {any} The minimum value, which must not be greater than its maximum (max attribute) value.
  130. */
  131. _this.min = null;
  132. /**
  133. * @input {any} The maximum value, which must not be less than its minimum (min attribute) value.
  134. */
  135. _this.max = null;
  136. /**
  137. * @input {any} Works with the min and max attributes to limit the increments at which a value can be set.
  138. */
  139. _this.step = null;
  140. /**
  141. * @hidden
  142. */
  143. _this.input = new core_1.EventEmitter();
  144. /**
  145. * @hidden
  146. */
  147. _this.blur = new core_1.EventEmitter();
  148. /**
  149. * @hidden
  150. */
  151. _this.focus = new core_1.EventEmitter();
  152. _this.autocomplete = config.get('autocomplete', 'off');
  153. _this.autocorrect = config.get('autocorrect', 'off');
  154. _this._autoFocusAssist = config.get('autoFocusAssist', 'delay');
  155. _this._keyboardHeight = config.getNumber('keyboardHeight');
  156. _this._isTextarea = !!(elementRef.nativeElement.tagName === 'ION-TEXTAREA');
  157. if (_this._isTextarea && _item) {
  158. _item.setElementClass('item-textarea', true);
  159. }
  160. // If not inside content, let's disable all the hacks
  161. if (!_content) {
  162. return _this;
  163. }
  164. var hideCaretOnScroll = config.getBoolean('hideCaretOnScroll', false);
  165. if (hideCaretOnScroll) {
  166. _this._enableHideCaretOnScroll();
  167. }
  168. var win = _plt.win();
  169. var keyboardPlugin = win.Ionic && win.Ionic.keyboardPlugin;
  170. if (keyboardPlugin) {
  171. var keyboardResizes = config.getBoolean('keyboardResizes', false);
  172. if (keyboardResizes) {
  173. _this._keyboardHeight = config.getNumber('keyboardSafeArea', 60);
  174. _this._enableScrollMove();
  175. }
  176. else {
  177. _this._enableScrollPadding();
  178. _this._enableScrollMove();
  179. }
  180. }
  181. else {
  182. _this._useAssist = config.getBoolean('scrollAssist', false);
  183. var usePadding = config.getBoolean('scrollPadding', _this._useAssist);
  184. if (usePadding) {
  185. _this._enableScrollPadding();
  186. }
  187. }
  188. return _this;
  189. }
  190. Object.defineProperty(TextInput.prototype, "clearInput", {
  191. /**
  192. * @input {boolean} If true, a clear icon will appear in the input when there is a value. Clicking it clears the input.
  193. */
  194. get: function () {
  195. return this._clearInput;
  196. },
  197. set: function (val) {
  198. this._clearInput = (!this._isTextarea && util_1.isTrueProperty(val));
  199. },
  200. enumerable: true,
  201. configurable: true
  202. });
  203. Object.defineProperty(TextInput.prototype, "type", {
  204. /**
  205. * @input {string} The type of control to display. The default type is text.
  206. * Possible values are: `"text"`, `"password"`, `"email"`, `"number"`, `"search"`, `"tel"`, or `"url"`.
  207. */
  208. get: function () {
  209. return (this._isTextarea)
  210. ? 'text'
  211. : this._type;
  212. },
  213. set: function (val) {
  214. this._type = val;
  215. },
  216. enumerable: true,
  217. configurable: true
  218. });
  219. Object.defineProperty(TextInput.prototype, "readonly", {
  220. /**
  221. * @input {boolean} If true, the user cannot modify the value.
  222. */
  223. get: function () {
  224. return this._readonly;
  225. },
  226. set: function (val) {
  227. this._readonly = util_1.isTrueProperty(val);
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(TextInput.prototype, "clearOnEdit", {
  233. /**
  234. * @input {boolean} If true, the value will be cleared after focus upon edit.
  235. * Defaults to `true` when `type` is `"password"`, `false` for all other types.
  236. */
  237. get: function () {
  238. return this._clearOnEdit;
  239. },
  240. set: function (val) {
  241. this._clearOnEdit = util_1.isTrueProperty(val);
  242. },
  243. enumerable: true,
  244. configurable: true
  245. });
  246. TextInput.prototype.ngAfterContentInit = function () { };
  247. /**
  248. * @hidden
  249. */
  250. TextInput.prototype.ngAfterViewInit = function () {
  251. (void 0) /* assert */;
  252. // By default, password inputs clear after focus when they have content
  253. if (this.clearOnEdit !== false && this.type === 'password') {
  254. this.clearOnEdit = true;
  255. }
  256. var ionInputEle = this._elementRef.nativeElement;
  257. var nativeInputEle = this._native.nativeElement;
  258. // Copy remaining attributes, not handled by ionic/angular
  259. dom_1.copyInputAttributes(ionInputEle, nativeInputEle);
  260. // prevent having tabIndex duplicated
  261. if (ionInputEle.hasAttribute('tabIndex')) {
  262. ionInputEle.removeAttribute('tabIndex');
  263. }
  264. // handle the autofocus attribute
  265. if (ionInputEle.hasAttribute('autofocus')) {
  266. ionInputEle.removeAttribute('autofocus');
  267. switch (this._autoFocusAssist) {
  268. case 'immediate':
  269. // config says to immediate focus on the input
  270. // works best on android devices
  271. nativeInputEle.focus();
  272. break;
  273. case 'delay':
  274. // config says to chill out a bit and focus on the input after transitions
  275. // works best on desktop
  276. this._plt.timeout(function () { return nativeInputEle.focus(); }, 800);
  277. break;
  278. }
  279. // traditionally iOS has big issues with autofocus on actual devices
  280. // autoFocus is disabled by default with the iOS mode config
  281. }
  282. // Initialize the input (can start emitting events)
  283. this._initialize();
  284. if (this.focus.observers.length > 0) {
  285. console.warn('(focus) is deprecated in ion-input, use (ionFocus) instead');
  286. }
  287. if (this.blur.observers.length > 0) {
  288. console.warn('(blur) is deprecated in ion-input, use (ionBlur) instead');
  289. }
  290. };
  291. /**
  292. * @hidden
  293. */
  294. TextInput.prototype.ngOnDestroy = function () {
  295. _super.prototype.ngOnDestroy.call(this);
  296. this._onDestroy.next();
  297. this._onDestroy = null;
  298. };
  299. /**
  300. * @hidden
  301. */
  302. TextInput.prototype.initFocus = function () {
  303. this.setFocus();
  304. };
  305. /**
  306. * @hidden
  307. */
  308. TextInput.prototype.setFocus = function () {
  309. // let's set focus to the element
  310. // but only if it does not already have focus
  311. if (!this.isFocus()) {
  312. this._native.nativeElement.focus();
  313. }
  314. };
  315. /**
  316. * @hidden
  317. */
  318. TextInput.prototype.setBlur = function () {
  319. if (this.isFocus()) {
  320. this._native.nativeElement.blur();
  321. }
  322. };
  323. /**
  324. * @hidden
  325. */
  326. TextInput.prototype.onInput = function (ev) {
  327. this.value = ev.target.value;
  328. // TODO: deprecate this
  329. this.input.emit(ev);
  330. };
  331. /**
  332. * @hidden
  333. */
  334. TextInput.prototype.onBlur = function (ev) {
  335. this._fireBlur();
  336. // TODO: deprecate this (06/07/2017)
  337. this.blur.emit(ev);
  338. this._scrollData = null;
  339. if (this._clearOnEdit && this.hasValue()) {
  340. this._didBlurAfterEdit = true;
  341. }
  342. };
  343. /**
  344. * @hidden
  345. */
  346. TextInput.prototype.onFocus = function (ev) {
  347. this._fireFocus();
  348. // TODO: deprecate this (06/07/2017)
  349. this.focus.emit(ev);
  350. };
  351. /**
  352. * @hidden
  353. */
  354. TextInput.prototype.onKeydown = function (ev) {
  355. if (ev && this._clearOnEdit) {
  356. this.checkClearOnEdit(ev.target.value);
  357. }
  358. };
  359. /**
  360. * @hidden
  361. */
  362. TextInput.prototype._inputUpdated = function () {
  363. _super.prototype._inputUpdated.call(this);
  364. var inputEle = this._native.nativeElement;
  365. var value = this._value;
  366. if (inputEle.value !== value) {
  367. inputEle.value = value;
  368. }
  369. };
  370. /**
  371. * @hidden
  372. */
  373. TextInput.prototype.clearTextInput = function () {
  374. this.value = '';
  375. };
  376. /**
  377. * Check if we need to clear the text input if clearOnEdit is enabled
  378. * @hidden
  379. */
  380. TextInput.prototype.checkClearOnEdit = function (_) {
  381. if (!this._clearOnEdit) {
  382. return;
  383. }
  384. // Did the input value change after it was blurred and edited?
  385. if (this._didBlurAfterEdit && this.hasValue()) {
  386. // Clear the input
  387. this.clearTextInput();
  388. }
  389. // Reset the flag
  390. this._didBlurAfterEdit = false;
  391. };
  392. TextInput.prototype._getScrollData = function () {
  393. if (!this._content) {
  394. return newScrollData();
  395. }
  396. // get container of this input, probably an ion-item a few nodes up
  397. if (this._scrollData) {
  398. return this._scrollData;
  399. }
  400. var ele = this._elementRef.nativeElement;
  401. ele = ele.closest('ion-item,[ion-item]') || ele;
  402. return this._scrollData = getScrollData(ele.offsetTop, ele.offsetHeight, this._content.getContentDimensions(), this._keyboardHeight, this._plt.height());
  403. };
  404. TextInput.prototype._relocateInput = function (shouldRelocate) {
  405. if (this._relocated === shouldRelocate) {
  406. return;
  407. }
  408. var platform = this._plt;
  409. var componentEle = this.getNativeElement();
  410. var focusedInputEle = this._native.nativeElement;
  411. (void 0) /* console.debug */;
  412. if (shouldRelocate) {
  413. // this allows for the actual input to receive the focus from
  414. // the user's touch event, but before it receives focus, it
  415. // moves the actual input to a location that will not screw
  416. // up the app's layout, and does not allow the native browser
  417. // to attempt to scroll the input into place (messing up headers/footers)
  418. // the cloned input fills the area of where native input should be
  419. // while the native input fakes out the browser by relocating itself
  420. // before it receives the actual focus event
  421. // We hide the focused input (with the visible caret) invisiable by making it scale(0),
  422. cloneInputComponent(platform, componentEle, focusedInputEle);
  423. var inputRelativeY = this._getScrollData().inputSafeY;
  424. // fix for #11817
  425. var tx = this._plt.isRTL ? 9999 : -9999;
  426. focusedInputEle.style[platform.Css.transform] = "translate3d(" + tx + "px," + inputRelativeY + "px,0)";
  427. focusedInputEle.style.opacity = '0';
  428. }
  429. else {
  430. removeClone(platform, componentEle, focusedInputEle);
  431. }
  432. this._relocated = shouldRelocate;
  433. };
  434. TextInput.prototype._enableScrollPadding = function () {
  435. var _this = this;
  436. (void 0) /* assert */;
  437. (void 0) /* console.debug */;
  438. this.ionFocus.subscribe(function () {
  439. var content = _this._content;
  440. var scrollPadding = _this._getScrollData().scrollPadding;
  441. content.addScrollPadding(scrollPadding);
  442. content.clearScrollPaddingFocusOut();
  443. });
  444. };
  445. TextInput.prototype._enableHideCaretOnScroll = function () {
  446. var _this = this;
  447. (void 0) /* assert */;
  448. var content = this._content;
  449. (void 0) /* console.debug */;
  450. content.ionScrollStart
  451. .takeUntil(this._onDestroy)
  452. .subscribe(function () { return scrollHideCaret(true); });
  453. content.ionScrollEnd
  454. .takeUntil(this._onDestroy)
  455. .subscribe(function () { return scrollHideCaret(false); });
  456. this.ionBlur.subscribe(function () { return _this._relocateInput(false); });
  457. var self = this;
  458. function scrollHideCaret(shouldHideCaret) {
  459. // if it does have focus, then do the dom write
  460. if (self.isFocus()) {
  461. self._dom.write(function () { return self._relocateInput(shouldHideCaret); });
  462. }
  463. }
  464. };
  465. TextInput.prototype._enableScrollMove = function () {
  466. var _this = this;
  467. (void 0) /* assert */;
  468. (void 0) /* console.debug */;
  469. this.ionFocus.subscribe(function () {
  470. var scrollData = _this._getScrollData();
  471. if (Math.abs(scrollData.scrollAmount) > 4) {
  472. _this._content.scrollTo(0, scrollData.scrollTo, scrollData.scrollDuration);
  473. }
  474. });
  475. };
  476. TextInput.prototype._pointerStart = function (ev) {
  477. (void 0) /* assert */;
  478. // input cover touchstart
  479. if (ev.type === 'touchstart') {
  480. this._isTouch = true;
  481. }
  482. if ((this._isTouch || (!this._isTouch && ev.type === 'mousedown')) && this._app.isEnabled()) {
  483. // remember where the touchstart/mousedown started
  484. this._coord = dom_1.pointerCoord(ev);
  485. }
  486. (void 0) /* console.debug */;
  487. };
  488. TextInput.prototype._pointerEnd = function (ev) {
  489. (void 0) /* assert */;
  490. // input cover touchend/mouseup
  491. (void 0) /* console.debug */;
  492. if ((this._isTouch && ev.type === 'mouseup') || !this._app.isEnabled()) {
  493. // the app is actively doing something right now
  494. // don't try to scroll in the input
  495. ev.preventDefault();
  496. ev.stopPropagation();
  497. }
  498. else if (this._coord) {
  499. // get where the touchend/mouseup ended
  500. var endCoord = dom_1.pointerCoord(ev);
  501. // focus this input if the pointer hasn't moved XX pixels
  502. // and the input doesn't already have focus
  503. if (!dom_1.hasPointerMoved(8, this._coord, endCoord) && !this.isFocus()) {
  504. ev.preventDefault();
  505. ev.stopPropagation();
  506. // begin the input focus process
  507. this._jsSetFocus();
  508. }
  509. }
  510. this._coord = null;
  511. };
  512. TextInput.prototype._jsSetFocus = function () {
  513. var _this = this;
  514. (void 0) /* assert */;
  515. // begin the process of setting focus to the inner input element
  516. var content = this._content;
  517. (void 0) /* console.debug */;
  518. if (!content) {
  519. // not inside of a scroll view, just focus it
  520. this.setFocus();
  521. }
  522. var scrollData = this._getScrollData();
  523. if (Math.abs(scrollData.scrollAmount) < 4) {
  524. // the text input is in a safe position that doesn't
  525. // require it to be scrolled into view, just set focus now
  526. this.setFocus();
  527. return;
  528. }
  529. // temporarily move the focus to the focus holder so the browser
  530. // doesn't freak out while it's trying to get the input in place
  531. // at this point the native text input still does not have focus
  532. this._relocateInput(true);
  533. this.setFocus();
  534. // scroll the input into place
  535. content.scrollTo(0, scrollData.scrollTo, scrollData.scrollDuration, function () {
  536. // the scroll view is in the correct position now
  537. // give the native text input focus
  538. _this._relocateInput(false);
  539. // ensure this is the focused input
  540. _this.setFocus();
  541. });
  542. };
  543. TextInput.decorators = [
  544. { type: core_1.Component, args: [{
  545. selector: 'ion-input,ion-textarea',
  546. template: '<input #textInput *ngIf="!_isTextarea" class="text-input" ' +
  547. '[ngClass]="\'text-input-\' + _mode"' +
  548. '(input)="onInput($event)" ' +
  549. '(blur)="onBlur($event)" ' +
  550. '(focus)="onFocus($event)" ' +
  551. '(keydown)="onKeydown($event)" ' +
  552. '[type]="_type" ' +
  553. 'dir="auto" ' +
  554. '[attr.aria-labelledby]="_labelId" ' +
  555. '[attr.min]="min" ' +
  556. '[attr.max]="max" ' +
  557. '[attr.step]="step" ' +
  558. '[attr.autocomplete]="autocomplete" ' +
  559. '[attr.autocorrect]="autocorrect" ' +
  560. '[placeholder]="placeholder" ' +
  561. '[disabled]="_disabled" ' +
  562. '[readonly]="_readonly">' +
  563. '<textarea #textInput *ngIf="_isTextarea" class="text-input" ' +
  564. '[ngClass]="\'text-input-\' + _mode"' +
  565. '(input)="onInput($event)" ' +
  566. '(blur)="onBlur($event)" ' +
  567. '(focus)="onFocus($event)" ' +
  568. '(keydown)="onKeydown($event)" ' +
  569. '[attr.aria-labelledby]="_labelId" ' +
  570. '[attr.autocomplete]="autocomplete" ' +
  571. '[attr.autocorrect]="autocorrect" ' +
  572. '[placeholder]="placeholder" ' +
  573. '[disabled]="_disabled" ' +
  574. '[readonly]="_readonly"></textarea>' +
  575. '<button ion-button *ngIf="_clearInput" clear class="text-input-clear-icon" ' +
  576. 'type="button" ' +
  577. '(click)="clearTextInput($event)" ' +
  578. '(mousedown)="clearTextInput($event)" ' +
  579. 'tabindex="-1"></button>' +
  580. '<div class="input-cover" *ngIf="_useAssist" ' +
  581. '(touchstart)="_pointerStart($event)" ' +
  582. '(touchend)="_pointerEnd($event)" ' +
  583. '(mousedown)="_pointerStart($event)" ' +
  584. '(mouseup)="_pointerEnd($event)"></div>',
  585. encapsulation: core_1.ViewEncapsulation.None,
  586. changeDetection: core_1.ChangeDetectionStrategy.OnPush,
  587. inputs: ['value']
  588. },] },
  589. ];
  590. /** @nocollapse */
  591. TextInput.ctorParameters = function () { return [
  592. { type: config_1.Config, },
  593. { type: platform_1.Platform, },
  594. { type: form_1.Form, },
  595. { type: app_1.App, },
  596. { type: core_1.ElementRef, },
  597. { type: core_1.Renderer, },
  598. { type: content_1.Content, decorators: [{ type: core_1.Optional },] },
  599. { type: item_1.Item, decorators: [{ type: core_1.Optional },] },
  600. { type: forms_1.NgControl, decorators: [{ type: core_1.Optional },] },
  601. { type: dom_controller_1.DomController, },
  602. ]; };
  603. TextInput.propDecorators = {
  604. 'clearInput': [{ type: core_1.Input },],
  605. 'type': [{ type: core_1.Input },],
  606. 'readonly': [{ type: core_1.Input },],
  607. 'clearOnEdit': [{ type: core_1.Input },],
  608. '_native': [{ type: core_1.ViewChild, args: ['textInput', { read: core_1.ElementRef },] },],
  609. 'autocomplete': [{ type: core_1.Input },],
  610. 'autocorrect': [{ type: core_1.Input },],
  611. 'placeholder': [{ type: core_1.Input },],
  612. 'min': [{ type: core_1.Input },],
  613. 'max': [{ type: core_1.Input },],
  614. 'step': [{ type: core_1.Input },],
  615. 'input': [{ type: core_1.Output },],
  616. 'blur': [{ type: core_1.Output },],
  617. 'focus': [{ type: core_1.Output },],
  618. };
  619. return TextInput;
  620. }(base_input_1.BaseInput));
  621. exports.TextInput = TextInput;
  622. /**
  623. * @name TextArea
  624. * @description
  625. *
  626. * `ion-textarea` is used for multi-line text inputs. Ionic still
  627. * uses an actual `<textarea>` HTML element within the component;
  628. * however, with Ionic wrapping the native HTML text area element, Ionic
  629. * is able to better handle the user experience and interactivity.
  630. *
  631. * Note that `<ion-textarea>` must load its value from the `value` or
  632. * `[(ngModel)]` attribute. Unlike the native `<textarea>` element,
  633. * `<ion-textarea>` does not support loading its value from the
  634. * textarea's inner content.
  635. *
  636. * When requiring only a single-line text input, we recommend using
  637. * `<ion-input>` instead.
  638. *
  639. * @usage
  640. * ```html
  641. * <ion-item>
  642. * <ion-label>Comments</ion-label>
  643. * <ion-textarea></ion-textarea>
  644. * </ion-item>
  645. *
  646. * <ion-item>
  647. * <ion-label stacked>Message</ion-label>
  648. * <ion-textarea [(ngModel)]="msg"></ion-textarea>
  649. * </ion-item>
  650. *
  651. * <ion-item>
  652. * <ion-label floating>Description</ion-label>
  653. * <ion-textarea></ion-textarea>
  654. * </ion-item>
  655. *
  656. * <ion-item>
  657. * <ion-label>Long Description</ion-label>
  658. * <ion-textarea rows="6" placeholder="enter long description here..."></ion-textarea>
  659. * </ion-item>
  660. * ```
  661. *
  662. * @demo /docs/demos/src/textarea/
  663. */
  664. var SCROLL_ASSIST_SPEED = 0.3;
  665. function newScrollData() {
  666. return {
  667. scrollAmount: 0,
  668. scrollTo: 0,
  669. scrollPadding: 0,
  670. scrollDuration: 0,
  671. inputSafeY: 0
  672. };
  673. }
  674. /**
  675. * @hidden
  676. */
  677. function getScrollData(inputOffsetTop, inputOffsetHeight, scrollViewDimensions, keyboardHeight, plaformHeight) {
  678. // compute input's Y values relative to the body
  679. var inputTop = (inputOffsetTop + scrollViewDimensions.contentTop - scrollViewDimensions.scrollTop);
  680. var inputBottom = (inputTop + inputOffsetHeight);
  681. // compute the safe area which is the viewable content area when the soft keyboard is up
  682. var safeAreaTop = scrollViewDimensions.contentTop;
  683. var safeAreaHeight = (plaformHeight - keyboardHeight - safeAreaTop) / 2;
  684. var safeAreaBottom = safeAreaTop + safeAreaHeight;
  685. // figure out if each edge of teh input is within the safe area
  686. var inputTopWithinSafeArea = (inputTop >= safeAreaTop && inputTop <= safeAreaBottom);
  687. var inputTopAboveSafeArea = (inputTop < safeAreaTop);
  688. var inputTopBelowSafeArea = (inputTop > safeAreaBottom);
  689. var inputBottomWithinSafeArea = (inputBottom >= safeAreaTop && inputBottom <= safeAreaBottom);
  690. var inputBottomBelowSafeArea = (inputBottom > safeAreaBottom);
  691. /*
  692. Text Input Scroll To Scenarios
  693. ---------------------------------------
  694. 1) Input top within safe area, bottom within safe area
  695. 2) Input top within safe area, bottom below safe area, room to scroll
  696. 3) Input top above safe area, bottom within safe area, room to scroll
  697. 4) Input top below safe area, no room to scroll, input smaller than safe area
  698. 5) Input top within safe area, bottom below safe area, no room to scroll, input smaller than safe area
  699. 6) Input top within safe area, bottom below safe area, no room to scroll, input larger than safe area
  700. 7) Input top below safe area, no room to scroll, input larger than safe area
  701. */
  702. var scrollData = newScrollData();
  703. // when auto-scrolling, there also needs to be enough
  704. // content padding at the bottom of the scroll view
  705. // always add scroll padding when a text input has focus
  706. // this allows for the content to scroll above of the keyboard
  707. // content behind the keyboard would be blank
  708. // some cases may not need it, but when jumping around it's best
  709. // to have the padding already rendered so there's no jank
  710. scrollData.scrollPadding = keyboardHeight;
  711. if (inputTopWithinSafeArea && inputBottomWithinSafeArea) {
  712. // Input top within safe area, bottom within safe area
  713. // no need to scroll to a position, it's good as-is
  714. return scrollData;
  715. }
  716. // looks like we'll have to do some auto-scrolling
  717. if (inputTopBelowSafeArea || inputBottomBelowSafeArea || inputTopAboveSafeArea) {
  718. // Input top or bottom below safe area
  719. // auto scroll the input up so at least the top of it shows
  720. if (safeAreaHeight > inputOffsetHeight) {
  721. // safe area height is taller than the input height, so we
  722. // can bring up the input just enough to show the input bottom
  723. scrollData.scrollAmount = Math.round(safeAreaBottom - inputBottom);
  724. }
  725. else {
  726. // safe area height is smaller than the input height, so we can
  727. // only scroll it up so the input top is at the top of the safe area
  728. // however the input bottom will be below the safe area
  729. scrollData.scrollAmount = Math.round(safeAreaTop - inputTop);
  730. }
  731. scrollData.inputSafeY = -(inputTop - safeAreaTop) + 4;
  732. if (inputTopAboveSafeArea && scrollData.scrollAmount > inputOffsetHeight) {
  733. // the input top is above the safe area and we're already scrolling it into place
  734. // don't let it scroll more than the height of the input
  735. scrollData.scrollAmount = inputOffsetHeight;
  736. }
  737. }
  738. // figure out where it should scroll to for the best position to the input
  739. scrollData.scrollTo = (scrollViewDimensions.scrollTop - scrollData.scrollAmount);
  740. // calculate animation duration
  741. var distance = Math.abs(scrollData.scrollAmount);
  742. var duration = distance / SCROLL_ASSIST_SPEED;
  743. scrollData.scrollDuration = Math.min(400, Math.max(150, duration));
  744. return scrollData;
  745. }
  746. exports.getScrollData = getScrollData;
  747. function cloneInputComponent(plt, srcComponentEle, srcNativeInputEle) {
  748. // Make sure we kill all the clones before creating new ones
  749. // It is a defensive, removeClone() should do nothing
  750. // removeClone(plt, srcComponentEle, srcNativeInputEle);
  751. (void 0) /* assert */;
  752. // given a native <input> or <textarea> element
  753. // find its parent wrapping component like <ion-input> or <ion-textarea>
  754. // then clone the entire component
  755. if (srcComponentEle) {
  756. // DOM READ
  757. var srcTop = srcComponentEle.offsetTop;
  758. var srcLeft = srcComponentEle.offsetLeft;
  759. var srcWidth = srcComponentEle.offsetWidth;
  760. var srcHeight = srcComponentEle.offsetHeight;
  761. // DOM WRITE
  762. // not using deep clone so we don't pull in unnecessary nodes
  763. var clonedComponentEle = srcComponentEle.cloneNode(false);
  764. var clonedStyle = clonedComponentEle.style;
  765. clonedComponentEle.classList.add('cloned-input');
  766. clonedComponentEle.setAttribute('aria-hidden', 'true');
  767. clonedStyle.pointerEvents = 'none';
  768. clonedStyle.position = 'absolute';
  769. clonedStyle.top = srcTop + 'px';
  770. clonedStyle.left = srcLeft + 'px';
  771. clonedStyle.width = srcWidth + 'px';
  772. clonedStyle.height = srcHeight + 'px';
  773. var clonedNativeInputEle = srcNativeInputEle.cloneNode(false);
  774. clonedNativeInputEle.value = srcNativeInputEle.value;
  775. clonedNativeInputEle.tabIndex = -1;
  776. clonedComponentEle.appendChild(clonedNativeInputEle);
  777. srcComponentEle.parentNode.appendChild(clonedComponentEle);
  778. srcComponentEle.style.pointerEvents = 'none';
  779. }
  780. srcNativeInputEle.style[plt.Css.transform] = 'scale(0)';
  781. }
  782. function removeClone(plt, srcComponentEle, srcNativeInputEle) {
  783. if (srcComponentEle && srcComponentEle.parentElement) {
  784. var clonedInputEles = srcComponentEle.parentElement.querySelectorAll('.cloned-input');
  785. for (var i = 0; i < clonedInputEles.length; i++) {
  786. clonedInputEles[i].parentNode.removeChild(clonedInputEles[i]);
  787. }
  788. srcComponentEle.style.pointerEvents = '';
  789. }
  790. srcNativeInputEle.style[plt.Css.transform] = '';
  791. srcNativeInputEle.style.opacity = '';
  792. }
  793. });
  794. //# sourceMappingURL=input.js.map