cdk-stepper.umd.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  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. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/cdk/a11y'), require('@angular/cdk/bidi'), require('@angular/cdk/coercion'), require('@angular/cdk/keycodes'), require('@angular/common'), require('rxjs'), require('rxjs/operators')) :
  10. typeof define === 'function' && define.amd ? define('@angular/cdk/stepper', ['exports', '@angular/core', '@angular/cdk/a11y', '@angular/cdk/bidi', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/common', 'rxjs', 'rxjs/operators'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.stepper = {}),global.ng.core,global.ng.cdk.a11y,global.ng.cdk.bidi,global.ng.cdk.coercion,global.ng.cdk.keycodes,global.ng.common,global.rxjs,global.rxjs.operators));
  12. }(this, (function (exports,core,a11y,bidi,coercion,keycodes,common,rxjs,operators) { 'use strict';
  13. /**
  14. * @fileoverview added by tsickle
  15. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  16. */
  17. var CdkStepHeader = /** @class */ (function () {
  18. function CdkStepHeader(_elementRef) {
  19. this._elementRef = _elementRef;
  20. }
  21. /** Focuses the step header. */
  22. /**
  23. * Focuses the step header.
  24. * @return {?}
  25. */
  26. CdkStepHeader.prototype.focus = /**
  27. * Focuses the step header.
  28. * @return {?}
  29. */
  30. function () {
  31. this._elementRef.nativeElement.focus();
  32. };
  33. CdkStepHeader.decorators = [
  34. { type: core.Directive, args: [{
  35. selector: '[cdkStepHeader]',
  36. host: {
  37. 'role': 'tab',
  38. },
  39. },] },
  40. ];
  41. /** @nocollapse */
  42. CdkStepHeader.ctorParameters = function () { return [
  43. { type: core.ElementRef }
  44. ]; };
  45. return CdkStepHeader;
  46. }());
  47. /**
  48. * @fileoverview added by tsickle
  49. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  50. */
  51. var CdkStepLabel = /** @class */ (function () {
  52. function CdkStepLabel(/** @docs-private */ template) {
  53. this.template = template;
  54. }
  55. CdkStepLabel.decorators = [
  56. { type: core.Directive, args: [{
  57. selector: '[cdkStepLabel]',
  58. },] },
  59. ];
  60. /** @nocollapse */
  61. CdkStepLabel.ctorParameters = function () { return [
  62. { type: core.TemplateRef }
  63. ]; };
  64. return CdkStepLabel;
  65. }());
  66. /**
  67. * @fileoverview added by tsickle
  68. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  69. */
  70. /**
  71. * Used to generate unique ID for each stepper component.
  72. * @type {?}
  73. */
  74. var nextId = 0;
  75. /**
  76. * Change event emitted on selection changes.
  77. */
  78. var /**
  79. * Change event emitted on selection changes.
  80. */
  81. StepperSelectionEvent = /** @class */ (function () {
  82. function StepperSelectionEvent() {
  83. }
  84. return StepperSelectionEvent;
  85. }());
  86. /**
  87. * Enum to represent the different states of the steps.
  88. * @type {?}
  89. */
  90. var STEP_STATE = {
  91. NUMBER: 'number',
  92. EDIT: 'edit',
  93. DONE: 'done',
  94. ERROR: 'error'
  95. };
  96. /**
  97. * InjectionToken that can be used to specify the global stepper options.
  98. * @type {?}
  99. */
  100. var STEPPER_GLOBAL_OPTIONS = new core.InjectionToken('STEPPER_GLOBAL_OPTIONS');
  101. /**
  102. * InjectionToken that can be used to specify the global stepper options.
  103. * @deprecated Use `STEPPER_GLOBAL_OPTIONS` instead.
  104. * \@breaking-change 8.0.0.
  105. * @type {?}
  106. */
  107. var MAT_STEPPER_GLOBAL_OPTIONS = STEPPER_GLOBAL_OPTIONS;
  108. var CdkStep = /** @class */ (function () {
  109. /** @breaking-change 8.0.0 remove the `?` after `stepperOptions` */
  110. function CdkStep(_stepper, stepperOptions) {
  111. this._stepper = _stepper;
  112. /**
  113. * Whether user has seen the expanded step content or not.
  114. */
  115. this.interacted = false;
  116. this._editable = true;
  117. this._optional = false;
  118. this._completedOverride = null;
  119. this._customError = null;
  120. this._stepperOptions = stepperOptions ? stepperOptions : {};
  121. this._displayDefaultIndicatorType = this._stepperOptions.displayDefaultIndicatorType !== false;
  122. this._showError = !!this._stepperOptions.showError;
  123. }
  124. Object.defineProperty(CdkStep.prototype, "editable", {
  125. /** Whether the user can return to this step once it has been marked as completed. */
  126. get: /**
  127. * Whether the user can return to this step once it has been marked as completed.
  128. * @return {?}
  129. */
  130. function () {
  131. return this._editable;
  132. },
  133. set: /**
  134. * @param {?} value
  135. * @return {?}
  136. */
  137. function (value) {
  138. this._editable = coercion.coerceBooleanProperty(value);
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(CdkStep.prototype, "optional", {
  144. /** Whether the completion of step is optional. */
  145. get: /**
  146. * Whether the completion of step is optional.
  147. * @return {?}
  148. */
  149. function () {
  150. return this._optional;
  151. },
  152. set: /**
  153. * @param {?} value
  154. * @return {?}
  155. */
  156. function (value) {
  157. this._optional = coercion.coerceBooleanProperty(value);
  158. },
  159. enumerable: true,
  160. configurable: true
  161. });
  162. Object.defineProperty(CdkStep.prototype, "completed", {
  163. /** Whether step is marked as completed. */
  164. get: /**
  165. * Whether step is marked as completed.
  166. * @return {?}
  167. */
  168. function () {
  169. return this._completedOverride == null ? this._getDefaultCompleted() : this._completedOverride;
  170. },
  171. set: /**
  172. * @param {?} value
  173. * @return {?}
  174. */
  175. function (value) {
  176. this._completedOverride = coercion.coerceBooleanProperty(value);
  177. },
  178. enumerable: true,
  179. configurable: true
  180. });
  181. /**
  182. * @private
  183. * @return {?}
  184. */
  185. CdkStep.prototype._getDefaultCompleted = /**
  186. * @private
  187. * @return {?}
  188. */
  189. function () {
  190. return this.stepControl ? this.stepControl.valid && this.interacted : this.interacted;
  191. };
  192. Object.defineProperty(CdkStep.prototype, "hasError", {
  193. /** Whether step has an error. */
  194. get: /**
  195. * Whether step has an error.
  196. * @return {?}
  197. */
  198. function () {
  199. return this._customError == null ? this._getDefaultError() : this._customError;
  200. },
  201. set: /**
  202. * @param {?} value
  203. * @return {?}
  204. */
  205. function (value) {
  206. this._customError = coercion.coerceBooleanProperty(value);
  207. },
  208. enumerable: true,
  209. configurable: true
  210. });
  211. /**
  212. * @private
  213. * @return {?}
  214. */
  215. CdkStep.prototype._getDefaultError = /**
  216. * @private
  217. * @return {?}
  218. */
  219. function () {
  220. return this.stepControl && this.stepControl.invalid && this.interacted;
  221. };
  222. /** Selects this step component. */
  223. /**
  224. * Selects this step component.
  225. * @return {?}
  226. */
  227. CdkStep.prototype.select = /**
  228. * Selects this step component.
  229. * @return {?}
  230. */
  231. function () {
  232. this._stepper.selected = this;
  233. };
  234. /** Resets the step to its initial state. Note that this includes resetting form data. */
  235. /**
  236. * Resets the step to its initial state. Note that this includes resetting form data.
  237. * @return {?}
  238. */
  239. CdkStep.prototype.reset = /**
  240. * Resets the step to its initial state. Note that this includes resetting form data.
  241. * @return {?}
  242. */
  243. function () {
  244. this.interacted = false;
  245. if (this._completedOverride != null) {
  246. this._completedOverride = false;
  247. }
  248. if (this._customError != null) {
  249. this._customError = false;
  250. }
  251. if (this.stepControl) {
  252. this.stepControl.reset();
  253. }
  254. };
  255. /**
  256. * @return {?}
  257. */
  258. CdkStep.prototype.ngOnChanges = /**
  259. * @return {?}
  260. */
  261. function () {
  262. // Since basically all inputs of the MatStep get proxied through the view down to the
  263. // underlying MatStepHeader, we have to make sure that change detection runs correctly.
  264. this._stepper._stateChanged();
  265. };
  266. CdkStep.decorators = [
  267. { type: core.Component, args: [{selector: 'cdk-step',
  268. exportAs: 'cdkStep',
  269. template: '<ng-template><ng-content></ng-content></ng-template>',
  270. encapsulation: core.ViewEncapsulation.None,
  271. changeDetection: core.ChangeDetectionStrategy.OnPush,
  272. },] },
  273. ];
  274. /** @nocollapse */
  275. CdkStep.ctorParameters = function () { return [
  276. { type: CdkStepper, decorators: [{ type: core.Inject, args: [core.forwardRef((/**
  277. * @return {?}
  278. */
  279. function () { return CdkStepper; })),] }] },
  280. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [STEPPER_GLOBAL_OPTIONS,] }] }
  281. ]; };
  282. CdkStep.propDecorators = {
  283. stepLabel: [{ type: core.ContentChild, args: [CdkStepLabel, { static: false },] }],
  284. content: [{ type: core.ViewChild, args: [core.TemplateRef, { static: true },] }],
  285. stepControl: [{ type: core.Input }],
  286. label: [{ type: core.Input }],
  287. errorMessage: [{ type: core.Input }],
  288. ariaLabel: [{ type: core.Input, args: ['aria-label',] }],
  289. ariaLabelledby: [{ type: core.Input, args: ['aria-labelledby',] }],
  290. state: [{ type: core.Input }],
  291. editable: [{ type: core.Input }],
  292. optional: [{ type: core.Input }],
  293. completed: [{ type: core.Input }],
  294. hasError: [{ type: core.Input }]
  295. };
  296. return CdkStep;
  297. }());
  298. var CdkStepper = /** @class */ (function () {
  299. function CdkStepper(_dir, _changeDetectorRef, _elementRef, _document) {
  300. this._dir = _dir;
  301. this._changeDetectorRef = _changeDetectorRef;
  302. this._elementRef = _elementRef;
  303. /**
  304. * Emits when the component is destroyed.
  305. */
  306. this._destroyed = new rxjs.Subject();
  307. this._linear = false;
  308. this._selectedIndex = 0;
  309. /**
  310. * Event emitted when the selected step has changed.
  311. */
  312. this.selectionChange = new core.EventEmitter();
  313. this._orientation = 'horizontal';
  314. this._groupId = nextId++;
  315. this._document = _document;
  316. }
  317. Object.defineProperty(CdkStepper.prototype, "steps", {
  318. /** The list of step components that the stepper is holding. */
  319. get: /**
  320. * The list of step components that the stepper is holding.
  321. * @return {?}
  322. */
  323. function () {
  324. return this._steps;
  325. },
  326. enumerable: true,
  327. configurable: true
  328. });
  329. Object.defineProperty(CdkStepper.prototype, "linear", {
  330. /** Whether the validity of previous steps should be checked or not. */
  331. get: /**
  332. * Whether the validity of previous steps should be checked or not.
  333. * @return {?}
  334. */
  335. function () {
  336. return this._linear;
  337. },
  338. set: /**
  339. * @param {?} value
  340. * @return {?}
  341. */
  342. function (value) {
  343. this._linear = coercion.coerceBooleanProperty(value);
  344. },
  345. enumerable: true,
  346. configurable: true
  347. });
  348. Object.defineProperty(CdkStepper.prototype, "selectedIndex", {
  349. /** The index of the selected step. */
  350. get: /**
  351. * The index of the selected step.
  352. * @return {?}
  353. */
  354. function () {
  355. return this._selectedIndex;
  356. },
  357. set: /**
  358. * @param {?} index
  359. * @return {?}
  360. */
  361. function (index) {
  362. /** @type {?} */
  363. var newIndex = coercion.coerceNumberProperty(index);
  364. if (this.steps) {
  365. // Ensure that the index can't be out of bounds.
  366. if (newIndex < 0 || newIndex > this.steps.length - 1) {
  367. throw Error('cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.');
  368. }
  369. if (this._selectedIndex != newIndex && !this._anyControlsInvalidOrPending(newIndex) &&
  370. (newIndex >= this._selectedIndex || this.steps.toArray()[newIndex].editable)) {
  371. this._updateSelectedItemIndex(index);
  372. }
  373. }
  374. else {
  375. this._selectedIndex = newIndex;
  376. }
  377. },
  378. enumerable: true,
  379. configurable: true
  380. });
  381. Object.defineProperty(CdkStepper.prototype, "selected", {
  382. /** The step that is selected. */
  383. get: /**
  384. * The step that is selected.
  385. * @return {?}
  386. */
  387. function () {
  388. // @breaking-change 8.0.0 Change return type to `CdkStep | undefined`.
  389. return this.steps ? this.steps.toArray()[this.selectedIndex] : (/** @type {?} */ (undefined));
  390. },
  391. set: /**
  392. * @param {?} step
  393. * @return {?}
  394. */
  395. function (step) {
  396. this.selectedIndex = this.steps ? this.steps.toArray().indexOf(step) : -1;
  397. },
  398. enumerable: true,
  399. configurable: true
  400. });
  401. /**
  402. * @return {?}
  403. */
  404. CdkStepper.prototype.ngAfterViewInit = /**
  405. * @return {?}
  406. */
  407. function () {
  408. var _this = this;
  409. // Note that while the step headers are content children by default, any components that
  410. // extend this one might have them as view chidren. We initialize the keyboard handling in
  411. // AfterViewInit so we're guaranteed for both view and content children to be defined.
  412. this._keyManager = new a11y.FocusKeyManager(this._stepHeader)
  413. .withWrap()
  414. .withVerticalOrientation(this._orientation === 'vertical');
  415. (this._dir ? ((/** @type {?} */ (this._dir.change))) : rxjs.of())
  416. .pipe(operators.startWith(this._layoutDirection()), operators.takeUntil(this._destroyed))
  417. .subscribe((/**
  418. * @param {?} direction
  419. * @return {?}
  420. */
  421. function (direction) { return _this._keyManager.withHorizontalOrientation(direction); }));
  422. this._keyManager.updateActiveItemIndex(this._selectedIndex);
  423. this.steps.changes.pipe(operators.takeUntil(this._destroyed)).subscribe((/**
  424. * @return {?}
  425. */
  426. function () {
  427. if (!_this.selected) {
  428. _this._selectedIndex = Math.max(_this._selectedIndex - 1, 0);
  429. }
  430. }));
  431. };
  432. /**
  433. * @return {?}
  434. */
  435. CdkStepper.prototype.ngOnDestroy = /**
  436. * @return {?}
  437. */
  438. function () {
  439. this._destroyed.next();
  440. this._destroyed.complete();
  441. };
  442. /** Selects and focuses the next step in list. */
  443. /**
  444. * Selects and focuses the next step in list.
  445. * @return {?}
  446. */
  447. CdkStepper.prototype.next = /**
  448. * Selects and focuses the next step in list.
  449. * @return {?}
  450. */
  451. function () {
  452. this.selectedIndex = Math.min(this._selectedIndex + 1, this.steps.length - 1);
  453. };
  454. /** Selects and focuses the previous step in list. */
  455. /**
  456. * Selects and focuses the previous step in list.
  457. * @return {?}
  458. */
  459. CdkStepper.prototype.previous = /**
  460. * Selects and focuses the previous step in list.
  461. * @return {?}
  462. */
  463. function () {
  464. this.selectedIndex = Math.max(this._selectedIndex - 1, 0);
  465. };
  466. /** Resets the stepper to its initial state. Note that this includes clearing form data. */
  467. /**
  468. * Resets the stepper to its initial state. Note that this includes clearing form data.
  469. * @return {?}
  470. */
  471. CdkStepper.prototype.reset = /**
  472. * Resets the stepper to its initial state. Note that this includes clearing form data.
  473. * @return {?}
  474. */
  475. function () {
  476. this._updateSelectedItemIndex(0);
  477. this.steps.forEach((/**
  478. * @param {?} step
  479. * @return {?}
  480. */
  481. function (step) { return step.reset(); }));
  482. this._stateChanged();
  483. };
  484. /** Returns a unique id for each step label element. */
  485. /**
  486. * Returns a unique id for each step label element.
  487. * @param {?} i
  488. * @return {?}
  489. */
  490. CdkStepper.prototype._getStepLabelId = /**
  491. * Returns a unique id for each step label element.
  492. * @param {?} i
  493. * @return {?}
  494. */
  495. function (i) {
  496. return "cdk-step-label-" + this._groupId + "-" + i;
  497. };
  498. /** Returns unique id for each step content element. */
  499. /**
  500. * Returns unique id for each step content element.
  501. * @param {?} i
  502. * @return {?}
  503. */
  504. CdkStepper.prototype._getStepContentId = /**
  505. * Returns unique id for each step content element.
  506. * @param {?} i
  507. * @return {?}
  508. */
  509. function (i) {
  510. return "cdk-step-content-" + this._groupId + "-" + i;
  511. };
  512. /** Marks the component to be change detected. */
  513. /**
  514. * Marks the component to be change detected.
  515. * @return {?}
  516. */
  517. CdkStepper.prototype._stateChanged = /**
  518. * Marks the component to be change detected.
  519. * @return {?}
  520. */
  521. function () {
  522. this._changeDetectorRef.markForCheck();
  523. };
  524. /** Returns position state of the step with the given index. */
  525. /**
  526. * Returns position state of the step with the given index.
  527. * @param {?} index
  528. * @return {?}
  529. */
  530. CdkStepper.prototype._getAnimationDirection = /**
  531. * Returns position state of the step with the given index.
  532. * @param {?} index
  533. * @return {?}
  534. */
  535. function (index) {
  536. /** @type {?} */
  537. var position = index - this._selectedIndex;
  538. if (position < 0) {
  539. return this._layoutDirection() === 'rtl' ? 'next' : 'previous';
  540. }
  541. else if (position > 0) {
  542. return this._layoutDirection() === 'rtl' ? 'previous' : 'next';
  543. }
  544. return 'current';
  545. };
  546. /** Returns the type of icon to be displayed. */
  547. /**
  548. * Returns the type of icon to be displayed.
  549. * @param {?} index
  550. * @param {?=} state
  551. * @return {?}
  552. */
  553. CdkStepper.prototype._getIndicatorType = /**
  554. * Returns the type of icon to be displayed.
  555. * @param {?} index
  556. * @param {?=} state
  557. * @return {?}
  558. */
  559. function (index, state) {
  560. if (state === void 0) { state = STEP_STATE.NUMBER; }
  561. /** @type {?} */
  562. var step = this.steps.toArray()[index];
  563. /** @type {?} */
  564. var isCurrentStep = this._isCurrentStep(index);
  565. return step._displayDefaultIndicatorType ? this._getDefaultIndicatorLogic(step, isCurrentStep) :
  566. this._getGuidelineLogic(step, isCurrentStep, state);
  567. };
  568. /**
  569. * @private
  570. * @param {?} step
  571. * @param {?} isCurrentStep
  572. * @return {?}
  573. */
  574. CdkStepper.prototype._getDefaultIndicatorLogic = /**
  575. * @private
  576. * @param {?} step
  577. * @param {?} isCurrentStep
  578. * @return {?}
  579. */
  580. function (step, isCurrentStep) {
  581. if (step._showError && step.hasError && !isCurrentStep) {
  582. return STEP_STATE.ERROR;
  583. }
  584. else if (!step.completed || isCurrentStep) {
  585. return STEP_STATE.NUMBER;
  586. }
  587. else {
  588. return step.editable ? STEP_STATE.EDIT : STEP_STATE.DONE;
  589. }
  590. };
  591. /**
  592. * @private
  593. * @param {?} step
  594. * @param {?} isCurrentStep
  595. * @param {?=} state
  596. * @return {?}
  597. */
  598. CdkStepper.prototype._getGuidelineLogic = /**
  599. * @private
  600. * @param {?} step
  601. * @param {?} isCurrentStep
  602. * @param {?=} state
  603. * @return {?}
  604. */
  605. function (step, isCurrentStep, state) {
  606. if (state === void 0) { state = STEP_STATE.NUMBER; }
  607. if (step._showError && step.hasError && !isCurrentStep) {
  608. return STEP_STATE.ERROR;
  609. }
  610. else if (step.completed && !isCurrentStep) {
  611. return STEP_STATE.DONE;
  612. }
  613. else if (step.completed && isCurrentStep) {
  614. return state;
  615. }
  616. else if (step.editable && isCurrentStep) {
  617. return STEP_STATE.EDIT;
  618. }
  619. else {
  620. return state;
  621. }
  622. };
  623. /**
  624. * @private
  625. * @param {?} index
  626. * @return {?}
  627. */
  628. CdkStepper.prototype._isCurrentStep = /**
  629. * @private
  630. * @param {?} index
  631. * @return {?}
  632. */
  633. function (index) {
  634. return this._selectedIndex === index;
  635. };
  636. /** Returns the index of the currently-focused step header. */
  637. /**
  638. * Returns the index of the currently-focused step header.
  639. * @return {?}
  640. */
  641. CdkStepper.prototype._getFocusIndex = /**
  642. * Returns the index of the currently-focused step header.
  643. * @return {?}
  644. */
  645. function () {
  646. return this._keyManager ? this._keyManager.activeItemIndex : this._selectedIndex;
  647. };
  648. /**
  649. * @private
  650. * @param {?} newIndex
  651. * @return {?}
  652. */
  653. CdkStepper.prototype._updateSelectedItemIndex = /**
  654. * @private
  655. * @param {?} newIndex
  656. * @return {?}
  657. */
  658. function (newIndex) {
  659. /** @type {?} */
  660. var stepsArray = this.steps.toArray();
  661. this.selectionChange.emit({
  662. selectedIndex: newIndex,
  663. previouslySelectedIndex: this._selectedIndex,
  664. selectedStep: stepsArray[newIndex],
  665. previouslySelectedStep: stepsArray[this._selectedIndex],
  666. });
  667. // If focus is inside the stepper, move it to the next header, otherwise it may become
  668. // lost when the active step content is hidden. We can't be more granular with the check
  669. // (e.g. checking whether focus is inside the active step), because we don't have a
  670. // reference to the elements that are rendering out the content.
  671. this._containsFocus() ? this._keyManager.setActiveItem(newIndex) :
  672. this._keyManager.updateActiveItemIndex(newIndex);
  673. this._selectedIndex = newIndex;
  674. this._stateChanged();
  675. };
  676. /**
  677. * @param {?} event
  678. * @return {?}
  679. */
  680. CdkStepper.prototype._onKeydown = /**
  681. * @param {?} event
  682. * @return {?}
  683. */
  684. function (event) {
  685. /** @type {?} */
  686. var hasModifier = keycodes.hasModifierKey(event);
  687. /** @type {?} */
  688. var keyCode = event.keyCode;
  689. /** @type {?} */
  690. var manager = this._keyManager;
  691. if (manager.activeItemIndex != null && !hasModifier &&
  692. (keyCode === keycodes.SPACE || keyCode === keycodes.ENTER)) {
  693. this.selectedIndex = manager.activeItemIndex;
  694. event.preventDefault();
  695. }
  696. else if (keyCode === keycodes.HOME) {
  697. manager.setFirstItemActive();
  698. event.preventDefault();
  699. }
  700. else if (keyCode === keycodes.END) {
  701. manager.setLastItemActive();
  702. event.preventDefault();
  703. }
  704. else {
  705. manager.onKeydown(event);
  706. }
  707. };
  708. /**
  709. * @private
  710. * @param {?} index
  711. * @return {?}
  712. */
  713. CdkStepper.prototype._anyControlsInvalidOrPending = /**
  714. * @private
  715. * @param {?} index
  716. * @return {?}
  717. */
  718. function (index) {
  719. /** @type {?} */
  720. var steps = this.steps.toArray();
  721. steps[this._selectedIndex].interacted = true;
  722. if (this._linear && index >= 0) {
  723. return steps.slice(0, index).some((/**
  724. * @param {?} step
  725. * @return {?}
  726. */
  727. function (step) {
  728. /** @type {?} */
  729. var control = step.stepControl;
  730. /** @type {?} */
  731. var isIncomplete = control ? (control.invalid || control.pending || !step.interacted) : !step.completed;
  732. return isIncomplete && !step.optional && !step._completedOverride;
  733. }));
  734. }
  735. return false;
  736. };
  737. /**
  738. * @private
  739. * @return {?}
  740. */
  741. CdkStepper.prototype._layoutDirection = /**
  742. * @private
  743. * @return {?}
  744. */
  745. function () {
  746. return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr';
  747. };
  748. /** Checks whether the stepper contains the focused element. */
  749. /**
  750. * Checks whether the stepper contains the focused element.
  751. * @private
  752. * @return {?}
  753. */
  754. CdkStepper.prototype._containsFocus = /**
  755. * Checks whether the stepper contains the focused element.
  756. * @private
  757. * @return {?}
  758. */
  759. function () {
  760. if (!this._document || !this._elementRef) {
  761. return false;
  762. }
  763. /** @type {?} */
  764. var stepperElement = this._elementRef.nativeElement;
  765. /** @type {?} */
  766. var focusedElement = this._document.activeElement;
  767. return stepperElement === focusedElement || stepperElement.contains(focusedElement);
  768. };
  769. CdkStepper.decorators = [
  770. { type: core.Directive, args: [{
  771. selector: '[cdkStepper]',
  772. exportAs: 'cdkStepper',
  773. },] },
  774. ];
  775. /** @nocollapse */
  776. CdkStepper.ctorParameters = function () { return [
  777. { type: bidi.Directionality, decorators: [{ type: core.Optional }] },
  778. { type: core.ChangeDetectorRef },
  779. { type: core.ElementRef },
  780. { type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
  781. ]; };
  782. CdkStepper.propDecorators = {
  783. _steps: [{ type: core.ContentChildren, args: [CdkStep,] }],
  784. _stepHeader: [{ type: core.ContentChildren, args: [CdkStepHeader,] }],
  785. linear: [{ type: core.Input }],
  786. selectedIndex: [{ type: core.Input }],
  787. selected: [{ type: core.Input }],
  788. selectionChange: [{ type: core.Output }]
  789. };
  790. return CdkStepper;
  791. }());
  792. /**
  793. * @fileoverview added by tsickle
  794. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  795. */
  796. /**
  797. * Button that moves to the next step in a stepper workflow.
  798. */
  799. var CdkStepperNext = /** @class */ (function () {
  800. function CdkStepperNext(_stepper) {
  801. this._stepper = _stepper;
  802. /**
  803. * Type of the next button. Defaults to "submit" if not specified.
  804. */
  805. this.type = 'submit';
  806. }
  807. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  808. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  809. // ViewEngine they're overwritten.
  810. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  811. // tslint:disable-next-line:no-host-decorator-in-concrete
  812. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  813. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  814. // ViewEngine they're overwritten.
  815. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  816. // tslint:disable-next-line:no-host-decorator-in-concrete
  817. /**
  818. * @return {?}
  819. */
  820. CdkStepperNext.prototype._handleClick =
  821. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  822. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  823. // ViewEngine they're overwritten.
  824. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  825. // tslint:disable-next-line:no-host-decorator-in-concrete
  826. /**
  827. * @return {?}
  828. */
  829. function () {
  830. this._stepper.next();
  831. };
  832. CdkStepperNext.decorators = [
  833. { type: core.Directive, args: [{
  834. selector: 'button[cdkStepperNext]',
  835. host: {
  836. '[type]': 'type',
  837. }
  838. },] },
  839. ];
  840. /** @nocollapse */
  841. CdkStepperNext.ctorParameters = function () { return [
  842. { type: CdkStepper }
  843. ]; };
  844. CdkStepperNext.propDecorators = {
  845. type: [{ type: core.Input }],
  846. _handleClick: [{ type: core.HostListener, args: ['click',] }]
  847. };
  848. return CdkStepperNext;
  849. }());
  850. /**
  851. * Button that moves to the previous step in a stepper workflow.
  852. */
  853. var CdkStepperPrevious = /** @class */ (function () {
  854. function CdkStepperPrevious(_stepper) {
  855. this._stepper = _stepper;
  856. /**
  857. * Type of the previous button. Defaults to "button" if not specified.
  858. */
  859. this.type = 'button';
  860. }
  861. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  862. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  863. // ViewEngine they're overwritten.
  864. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  865. // tslint:disable-next-line:no-host-decorator-in-concrete
  866. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  867. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  868. // ViewEngine they're overwritten.
  869. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  870. // tslint:disable-next-line:no-host-decorator-in-concrete
  871. /**
  872. * @return {?}
  873. */
  874. CdkStepperPrevious.prototype._handleClick =
  875. // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
  876. // In Ivy the `host` bindings will be merged when this class is extended, whereas in
  877. // ViewEngine they're overwritten.
  878. // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
  879. // tslint:disable-next-line:no-host-decorator-in-concrete
  880. /**
  881. * @return {?}
  882. */
  883. function () {
  884. this._stepper.previous();
  885. };
  886. CdkStepperPrevious.decorators = [
  887. { type: core.Directive, args: [{
  888. selector: 'button[cdkStepperPrevious]',
  889. host: {
  890. '[type]': 'type',
  891. }
  892. },] },
  893. ];
  894. /** @nocollapse */
  895. CdkStepperPrevious.ctorParameters = function () { return [
  896. { type: CdkStepper }
  897. ]; };
  898. CdkStepperPrevious.propDecorators = {
  899. type: [{ type: core.Input }],
  900. _handleClick: [{ type: core.HostListener, args: ['click',] }]
  901. };
  902. return CdkStepperPrevious;
  903. }());
  904. /**
  905. * @fileoverview added by tsickle
  906. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  907. */
  908. var CdkStepperModule = /** @class */ (function () {
  909. function CdkStepperModule() {
  910. }
  911. CdkStepperModule.decorators = [
  912. { type: core.NgModule, args: [{
  913. imports: [bidi.BidiModule, common.CommonModule],
  914. exports: [
  915. CdkStep,
  916. CdkStepper,
  917. CdkStepHeader,
  918. CdkStepLabel,
  919. CdkStepperNext,
  920. CdkStepperPrevious,
  921. ],
  922. declarations: [
  923. CdkStep,
  924. CdkStepper,
  925. CdkStepHeader,
  926. CdkStepLabel,
  927. CdkStepperNext,
  928. CdkStepperPrevious,
  929. ]
  930. },] },
  931. ];
  932. return CdkStepperModule;
  933. }());
  934. exports.StepperSelectionEvent = StepperSelectionEvent;
  935. exports.STEP_STATE = STEP_STATE;
  936. exports.STEPPER_GLOBAL_OPTIONS = STEPPER_GLOBAL_OPTIONS;
  937. exports.MAT_STEPPER_GLOBAL_OPTIONS = MAT_STEPPER_GLOBAL_OPTIONS;
  938. exports.CdkStep = CdkStep;
  939. exports.CdkStepper = CdkStepper;
  940. exports.CdkStepLabel = CdkStepLabel;
  941. exports.CdkStepperNext = CdkStepperNext;
  942. exports.CdkStepperPrevious = CdkStepperPrevious;
  943. exports.CdkStepperModule = CdkStepperModule;
  944. exports.CdkStepHeader = CdkStepHeader;
  945. Object.defineProperty(exports, '__esModule', { value: true });
  946. })));
  947. //# sourceMappingURL=cdk-stepper.umd.js.map