expansion.es5.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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 { InjectionToken, Directive, TemplateRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, EventEmitter, ElementRef, Input, Inject, Optional, Output, SkipSelf, ViewContainerRef, ViewEncapsulation, ViewChild, Host, ContentChildren, NgModule } from '@angular/core';
  9. import { animate, animateChild, group, state, style, transition, trigger, query } from '@angular/animations';
  10. import { __extends } from 'tslib';
  11. import { CdkAccordionItem, CdkAccordion, CdkAccordionModule } from '@angular/cdk/accordion';
  12. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  13. import { UniqueSelectionDispatcher } from '@angular/cdk/collections';
  14. import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
  15. import { DOCUMENT, CommonModule } from '@angular/common';
  16. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  17. import { Subject, merge, Subscription, EMPTY } from 'rxjs';
  18. import { filter, startWith, take, distinctUntilChanged } from 'rxjs/operators';
  19. import { FocusMonitor, FocusKeyManager } from '@angular/cdk/a11y';
  20. import { ENTER, SPACE, hasModifierKey, HOME, END } from '@angular/cdk/keycodes';
  21. /**
  22. * @fileoverview added by tsickle
  23. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  24. */
  25. /**
  26. * Token used to provide a `MatAccordion` to `MatExpansionPanel`.
  27. * Used primarily to avoid circular imports between `MatAccordion` and `MatExpansionPanel`.
  28. * @type {?}
  29. */
  30. var MAT_ACCORDION = new InjectionToken('MAT_ACCORDION');
  31. /**
  32. * @fileoverview added by tsickle
  33. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  34. */
  35. /**
  36. * Time and timing curve for expansion panel animations.
  37. * @type {?}
  38. */
  39. var EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,1)';
  40. /**
  41. * Animations used by the Material expansion panel.
  42. *
  43. * A bug in angular animation's `state` when ViewContainers are moved using ViewContainerRef.move()
  44. * causes the animation state of moved components to become `void` upon exit, and not update again
  45. * upon reentry into the DOM. This can lead a to situation for the expansion panel where the state
  46. * of the panel is `expanded` or `collapsed` but the animation state is `void`.
  47. *
  48. * To correctly handle animating to the next state, we animate between `void` and `collapsed` which
  49. * are defined to have the same styles. Since angular animates from the current styles to the
  50. * destination state's style definition, in situations where we are moving from `void`'s styles to
  51. * `collapsed` this acts a noop since no style values change.
  52. *
  53. * In the case where angular's animation state is out of sync with the expansion panel's state, the
  54. * expansion panel being `expanded` and angular animations being `void`, the animation from the
  55. * `expanded`'s effective styles (though in a `void` animation state) to the collapsed state will
  56. * occur as expected.
  57. *
  58. * Angular Bug: https://github.com/angular/angular/issues/18847
  59. *
  60. * \@docs-private
  61. * @type {?}
  62. */
  63. var matExpansionAnimations = {
  64. /**
  65. * Animation that rotates the indicator arrow.
  66. */
  67. indicatorRotate: trigger('indicatorRotate', [
  68. state('collapsed, void', style({ transform: 'rotate(0deg)' })),
  69. state('expanded', style({ transform: 'rotate(180deg)' })),
  70. transition('expanded <=> collapsed, void => collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  71. ]),
  72. /**
  73. * Animation that expands and collapses the panel header height.
  74. */
  75. expansionHeaderHeight: trigger('expansionHeight', [
  76. state('collapsed, void', style({
  77. height: '{{collapsedHeight}}',
  78. }), {
  79. params: { collapsedHeight: '48px' },
  80. }),
  81. state('expanded', style({
  82. height: '{{expandedHeight}}'
  83. }), {
  84. params: { expandedHeight: '64px' }
  85. }),
  86. transition('expanded <=> collapsed, void => collapsed', group([
  87. query('@indicatorRotate', animateChild(), { optional: true }),
  88. animate(EXPANSION_PANEL_ANIMATION_TIMING),
  89. ])),
  90. ]),
  91. /**
  92. * Animation that expands and collapses the panel content.
  93. */
  94. bodyExpansion: trigger('bodyExpansion', [
  95. state('collapsed, void', style({ height: '0px', visibility: 'hidden' })),
  96. state('expanded', style({ height: '*', visibility: 'visible' })),
  97. transition('expanded <=> collapsed, void => collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  98. ])
  99. };
  100. /**
  101. * @fileoverview added by tsickle
  102. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  103. */
  104. /**
  105. * Expansion panel content that will be rendered lazily
  106. * after the panel is opened for the first time.
  107. */
  108. var MatExpansionPanelContent = /** @class */ (function () {
  109. function MatExpansionPanelContent(_template) {
  110. this._template = _template;
  111. }
  112. MatExpansionPanelContent.decorators = [
  113. { type: Directive, args: [{
  114. selector: 'ng-template[matExpansionPanelContent]'
  115. },] },
  116. ];
  117. /** @nocollapse */
  118. MatExpansionPanelContent.ctorParameters = function () { return [
  119. { type: TemplateRef }
  120. ]; };
  121. return MatExpansionPanelContent;
  122. }());
  123. /**
  124. * @fileoverview added by tsickle
  125. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  126. */
  127. /**
  128. * Counter for generating unique element ids.
  129. * @type {?}
  130. */
  131. var uniqueId = 0;
  132. /**
  133. * Injection token that can be used to configure the defalt
  134. * options for the expansion panel component.
  135. * @type {?}
  136. */
  137. var MAT_EXPANSION_PANEL_DEFAULT_OPTIONS = new InjectionToken('MAT_EXPANSION_PANEL_DEFAULT_OPTIONS');
  138. var ɵ0 = undefined;
  139. /**
  140. * `<mat-expansion-panel>`
  141. *
  142. * This component can be used as a single element to show expandable content, or as one of
  143. * multiple children of an element with the MatAccordion directive attached.
  144. */
  145. var MatExpansionPanel = /** @class */ (function (_super) {
  146. __extends(MatExpansionPanel, _super);
  147. function MatExpansionPanel(accordion, _changeDetectorRef, _uniqueSelectionDispatcher, _viewContainerRef, _document, _animationMode, defaultOptions) {
  148. var _this = _super.call(this, accordion, _changeDetectorRef, _uniqueSelectionDispatcher) || this;
  149. _this._viewContainerRef = _viewContainerRef;
  150. _this._animationMode = _animationMode;
  151. _this._hideToggle = false;
  152. /**
  153. * An event emitted after the body's expansion animation happens.
  154. */
  155. _this.afterExpand = new EventEmitter();
  156. /**
  157. * An event emitted after the body's collapse animation happens.
  158. */
  159. _this.afterCollapse = new EventEmitter();
  160. /**
  161. * Stream that emits for changes in `\@Input` properties.
  162. */
  163. _this._inputChanges = new Subject();
  164. /**
  165. * ID for the associated header element. Used for a11y labelling.
  166. */
  167. _this._headerId = "mat-expansion-panel-header-" + uniqueId++;
  168. /**
  169. * Stream of body animation done events.
  170. */
  171. _this._bodyAnimationDone = new Subject();
  172. _this.accordion = accordion;
  173. _this._document = _document;
  174. // We need a Subject with distinctUntilChanged, because the `done` event
  175. // fires twice on some browsers. See https://github.com/angular/angular/issues/24084
  176. _this._bodyAnimationDone.pipe(distinctUntilChanged((/**
  177. * @param {?} x
  178. * @param {?} y
  179. * @return {?}
  180. */
  181. function (x, y) {
  182. return x.fromState === y.fromState && x.toState === y.toState;
  183. }))).subscribe((/**
  184. * @param {?} event
  185. * @return {?}
  186. */
  187. function (event) {
  188. if (event.fromState !== 'void') {
  189. if (event.toState === 'expanded') {
  190. _this.afterExpand.emit();
  191. }
  192. else if (event.toState === 'collapsed') {
  193. _this.afterCollapse.emit();
  194. }
  195. }
  196. }));
  197. if (defaultOptions) {
  198. _this.hideToggle = defaultOptions.hideToggle;
  199. }
  200. return _this;
  201. }
  202. Object.defineProperty(MatExpansionPanel.prototype, "hideToggle", {
  203. /** Whether the toggle indicator should be hidden. */
  204. get: /**
  205. * Whether the toggle indicator should be hidden.
  206. * @return {?}
  207. */
  208. function () {
  209. return this._hideToggle || (this.accordion && this.accordion.hideToggle);
  210. },
  211. set: /**
  212. * @param {?} value
  213. * @return {?}
  214. */
  215. function (value) {
  216. this._hideToggle = coerceBooleanProperty(value);
  217. },
  218. enumerable: true,
  219. configurable: true
  220. });
  221. Object.defineProperty(MatExpansionPanel.prototype, "togglePosition", {
  222. /** The position of the expansion indicator. */
  223. get: /**
  224. * The position of the expansion indicator.
  225. * @return {?}
  226. */
  227. function () {
  228. return this._togglePosition || (this.accordion && this.accordion.togglePosition);
  229. },
  230. set: /**
  231. * @param {?} value
  232. * @return {?}
  233. */
  234. function (value) {
  235. this._togglePosition = value;
  236. },
  237. enumerable: true,
  238. configurable: true
  239. });
  240. /** Determines whether the expansion panel should have spacing between it and its siblings. */
  241. /**
  242. * Determines whether the expansion panel should have spacing between it and its siblings.
  243. * @return {?}
  244. */
  245. MatExpansionPanel.prototype._hasSpacing = /**
  246. * Determines whether the expansion panel should have spacing between it and its siblings.
  247. * @return {?}
  248. */
  249. function () {
  250. if (this.accordion) {
  251. // We don't need to subscribe to the `stateChanges` of the parent accordion because each time
  252. // the [displayMode] input changes, the change detection will also cover the host bindings
  253. // of this expansion panel.
  254. return (this.expanded ? this.accordion.displayMode : this._getExpandedState()) === 'default';
  255. }
  256. return false;
  257. };
  258. /** Gets the expanded state string. */
  259. /**
  260. * Gets the expanded state string.
  261. * @return {?}
  262. */
  263. MatExpansionPanel.prototype._getExpandedState = /**
  264. * Gets the expanded state string.
  265. * @return {?}
  266. */
  267. function () {
  268. return this.expanded ? 'expanded' : 'collapsed';
  269. };
  270. /**
  271. * @return {?}
  272. */
  273. MatExpansionPanel.prototype.ngAfterContentInit = /**
  274. * @return {?}
  275. */
  276. function () {
  277. var _this = this;
  278. if (this._lazyContent) {
  279. // Render the content as soon as the panel becomes open.
  280. this.opened.pipe(startWith((/** @type {?} */ (null))), filter((/**
  281. * @return {?}
  282. */
  283. function () { return _this.expanded && !_this._portal; })), take(1)).subscribe((/**
  284. * @return {?}
  285. */
  286. function () {
  287. _this._portal = new TemplatePortal(_this._lazyContent._template, _this._viewContainerRef);
  288. }));
  289. }
  290. };
  291. /**
  292. * @param {?} changes
  293. * @return {?}
  294. */
  295. MatExpansionPanel.prototype.ngOnChanges = /**
  296. * @param {?} changes
  297. * @return {?}
  298. */
  299. function (changes) {
  300. this._inputChanges.next(changes);
  301. };
  302. /**
  303. * @return {?}
  304. */
  305. MatExpansionPanel.prototype.ngOnDestroy = /**
  306. * @return {?}
  307. */
  308. function () {
  309. _super.prototype.ngOnDestroy.call(this);
  310. this._bodyAnimationDone.complete();
  311. this._inputChanges.complete();
  312. };
  313. /** Checks whether the expansion panel's content contains the currently-focused element. */
  314. /**
  315. * Checks whether the expansion panel's content contains the currently-focused element.
  316. * @return {?}
  317. */
  318. MatExpansionPanel.prototype._containsFocus = /**
  319. * Checks whether the expansion panel's content contains the currently-focused element.
  320. * @return {?}
  321. */
  322. function () {
  323. if (this._body) {
  324. /** @type {?} */
  325. var focusedElement = this._document.activeElement;
  326. /** @type {?} */
  327. var bodyElement = this._body.nativeElement;
  328. return focusedElement === bodyElement || bodyElement.contains(focusedElement);
  329. }
  330. return false;
  331. };
  332. MatExpansionPanel.decorators = [
  333. { type: Component, args: [{styles: [".mat-expansion-panel{box-sizing:content-box;display:block;margin:0;border-radius:4px;overflow:hidden;transition:margin 225ms cubic-bezier(.4,0,.2,1),box-shadow 280ms cubic-bezier(.4,0,.2,1)}.mat-accordion .mat-expansion-panel:not(.mat-expanded),.mat-accordion .mat-expansion-panel:not(.mat-expansion-panel-spacing){border-radius:0}.mat-accordion .mat-expansion-panel:first-of-type{border-top-right-radius:4px;border-top-left-radius:4px}.mat-accordion .mat-expansion-panel:last-of-type{border-bottom-right-radius:4px;border-bottom-left-radius:4px}@media (-ms-high-contrast:active){.mat-expansion-panel{outline:solid 1px}}.mat-expansion-panel._mat-animation-noopable,.mat-expansion-panel.ng-animate-disabled,.ng-animate-disabled .mat-expansion-panel{transition:none}.mat-expansion-panel-content{display:flex;flex-direction:column;overflow:visible}.mat-expansion-panel-body{padding:0 24px 16px}.mat-expansion-panel-spacing{margin:16px 0}.mat-accordion>.mat-expansion-panel-spacing:first-child,.mat-accordion>:first-child:not(.mat-expansion-panel) .mat-expansion-panel-spacing{margin-top:0}.mat-accordion>.mat-expansion-panel-spacing:last-child,.mat-accordion>:last-child:not(.mat-expansion-panel) .mat-expansion-panel-spacing{margin-bottom:0}.mat-action-row{border-top-style:solid;border-top-width:1px;display:flex;flex-direction:row;justify-content:flex-end;padding:16px 8px 16px 24px}.mat-action-row button.mat-button-base{margin-left:8px}[dir=rtl] .mat-action-row button.mat-button-base{margin-left:0;margin-right:8px}"],
  334. selector: 'mat-expansion-panel',
  335. exportAs: 'matExpansionPanel',
  336. template: "<ng-content select=\"mat-expansion-panel-header\"></ng-content><div class=\"mat-expansion-panel-content\" role=\"region\" [@bodyExpansion]=\"_getExpandedState()\" (@bodyExpansion.done)=\"_bodyAnimationDone.next($event)\" [attr.aria-labelledby]=\"_headerId\" [id]=\"id\" #body><div class=\"mat-expansion-panel-body\"><ng-content></ng-content><ng-template [cdkPortalOutlet]=\"_portal\"></ng-template></div><ng-content select=\"mat-action-row\"></ng-content></div>",
  337. encapsulation: ViewEncapsulation.None,
  338. changeDetection: ChangeDetectionStrategy.OnPush,
  339. inputs: ['disabled', 'expanded'],
  340. outputs: ['opened', 'closed', 'expandedChange'],
  341. animations: [matExpansionAnimations.bodyExpansion],
  342. providers: [
  343. // Provide MatAccordion as undefined to prevent nested expansion panels from registering
  344. // to the same accordion.
  345. { provide: MAT_ACCORDION, useValue: ɵ0 },
  346. ],
  347. host: {
  348. 'class': 'mat-expansion-panel',
  349. '[class.mat-expanded]': 'expanded',
  350. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  351. '[class.mat-expansion-panel-spacing]': '_hasSpacing()',
  352. }
  353. },] },
  354. ];
  355. /** @nocollapse */
  356. MatExpansionPanel.ctorParameters = function () { return [
  357. { type: undefined, decorators: [{ type: Optional }, { type: SkipSelf }, { type: Inject, args: [MAT_ACCORDION,] }] },
  358. { type: ChangeDetectorRef },
  359. { type: UniqueSelectionDispatcher },
  360. { type: ViewContainerRef },
  361. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
  362. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] },
  363. { type: undefined, decorators: [{ type: Inject, args: [MAT_EXPANSION_PANEL_DEFAULT_OPTIONS,] }, { type: Optional }] }
  364. ]; };
  365. MatExpansionPanel.propDecorators = {
  366. hideToggle: [{ type: Input }],
  367. togglePosition: [{ type: Input }],
  368. afterExpand: [{ type: Output }],
  369. afterCollapse: [{ type: Output }],
  370. _lazyContent: [{ type: ContentChild, args: [MatExpansionPanelContent, { static: false },] }],
  371. _body: [{ type: ViewChild, args: ['body', { static: false },] }]
  372. };
  373. return MatExpansionPanel;
  374. }(CdkAccordionItem));
  375. var MatExpansionPanelActionRow = /** @class */ (function () {
  376. function MatExpansionPanelActionRow() {
  377. }
  378. MatExpansionPanelActionRow.decorators = [
  379. { type: Directive, args: [{
  380. selector: 'mat-action-row',
  381. host: {
  382. class: 'mat-action-row'
  383. }
  384. },] },
  385. ];
  386. return MatExpansionPanelActionRow;
  387. }());
  388. /**
  389. * @fileoverview added by tsickle
  390. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  391. */
  392. /**
  393. * `<mat-expansion-panel-header>`
  394. *
  395. * This component corresponds to the header element of an `<mat-expansion-panel>`.
  396. */
  397. var MatExpansionPanelHeader = /** @class */ (function () {
  398. function MatExpansionPanelHeader(panel, _element, _focusMonitor, _changeDetectorRef, defaultOptions) {
  399. var _this = this;
  400. this.panel = panel;
  401. this._element = _element;
  402. this._focusMonitor = _focusMonitor;
  403. this._changeDetectorRef = _changeDetectorRef;
  404. this._parentChangeSubscription = Subscription.EMPTY;
  405. /**
  406. * Whether Angular animations in the panel header should be disabled.
  407. */
  408. this._animationsDisabled = true;
  409. /** @type {?} */
  410. var accordionHideToggleChange = panel.accordion ?
  411. panel.accordion._stateChanges.pipe(filter((/**
  412. * @param {?} changes
  413. * @return {?}
  414. */
  415. function (changes) { return !!(changes['hideToggle'] || changes['togglePosition']); }))) :
  416. EMPTY;
  417. // Since the toggle state depends on an @Input on the panel, we
  418. // need to subscribe and trigger change detection manually.
  419. this._parentChangeSubscription =
  420. merge(panel.opened, panel.closed, accordionHideToggleChange, panel._inputChanges.pipe(filter((/**
  421. * @param {?} changes
  422. * @return {?}
  423. */
  424. function (changes) {
  425. return !!(changes['hideToggle'] ||
  426. changes['disabled'] ||
  427. changes['togglePosition']);
  428. }))))
  429. .subscribe((/**
  430. * @return {?}
  431. */
  432. function () { return _this._changeDetectorRef.markForCheck(); }));
  433. // Avoids focus being lost if the panel contained the focused element and was closed.
  434. panel.closed
  435. .pipe(filter((/**
  436. * @return {?}
  437. */
  438. function () { return panel._containsFocus(); })))
  439. .subscribe((/**
  440. * @return {?}
  441. */
  442. function () { return _focusMonitor.focusVia(_element, 'program'); }));
  443. _focusMonitor.monitor(_element).subscribe((/**
  444. * @param {?} origin
  445. * @return {?}
  446. */
  447. function (origin) {
  448. if (origin && panel.accordion) {
  449. panel.accordion._handleHeaderFocus(_this);
  450. }
  451. }));
  452. if (defaultOptions) {
  453. this.expandedHeight = defaultOptions.expandedHeight;
  454. this.collapsedHeight = defaultOptions.collapsedHeight;
  455. }
  456. }
  457. /**
  458. * @return {?}
  459. */
  460. MatExpansionPanelHeader.prototype._animationStarted = /**
  461. * @return {?}
  462. */
  463. function () {
  464. // Currently the `expansionHeight` animation has a `void => collapsed` transition which is
  465. // there to work around a bug in Angular (see #13088), however this introduces a different
  466. // issue. The new transition will cause the header to animate in on init (see #16067), if the
  467. // consumer has set a header height that is different from the default one. We work around it
  468. // by disabling animations on the header and re-enabling them after the first animation has run.
  469. // Note that Angular dispatches animation events even if animations are disabled. Ideally this
  470. // wouldn't be necessary if we remove the `void => collapsed` transition, but we have to wait
  471. // for https://github.com/angular/angular/issues/18847 to be resolved.
  472. this._animationsDisabled = false;
  473. };
  474. Object.defineProperty(MatExpansionPanelHeader.prototype, "disabled", {
  475. /**
  476. * Whether the associated panel is disabled. Implemented as a part of `FocusableOption`.
  477. * @docs-private
  478. */
  479. get: /**
  480. * Whether the associated panel is disabled. Implemented as a part of `FocusableOption`.
  481. * \@docs-private
  482. * @return {?}
  483. */
  484. function () {
  485. return this.panel.disabled;
  486. },
  487. enumerable: true,
  488. configurable: true
  489. });
  490. /** Toggles the expanded state of the panel. */
  491. /**
  492. * Toggles the expanded state of the panel.
  493. * @return {?}
  494. */
  495. MatExpansionPanelHeader.prototype._toggle = /**
  496. * Toggles the expanded state of the panel.
  497. * @return {?}
  498. */
  499. function () {
  500. this.panel.toggle();
  501. };
  502. /** Gets whether the panel is expanded. */
  503. /**
  504. * Gets whether the panel is expanded.
  505. * @return {?}
  506. */
  507. MatExpansionPanelHeader.prototype._isExpanded = /**
  508. * Gets whether the panel is expanded.
  509. * @return {?}
  510. */
  511. function () {
  512. return this.panel.expanded;
  513. };
  514. /** Gets the expanded state string of the panel. */
  515. /**
  516. * Gets the expanded state string of the panel.
  517. * @return {?}
  518. */
  519. MatExpansionPanelHeader.prototype._getExpandedState = /**
  520. * Gets the expanded state string of the panel.
  521. * @return {?}
  522. */
  523. function () {
  524. return this.panel._getExpandedState();
  525. };
  526. /** Gets the panel id. */
  527. /**
  528. * Gets the panel id.
  529. * @return {?}
  530. */
  531. MatExpansionPanelHeader.prototype._getPanelId = /**
  532. * Gets the panel id.
  533. * @return {?}
  534. */
  535. function () {
  536. return this.panel.id;
  537. };
  538. /** Gets the toggle position for the header. */
  539. /**
  540. * Gets the toggle position for the header.
  541. * @return {?}
  542. */
  543. MatExpansionPanelHeader.prototype._getTogglePosition = /**
  544. * Gets the toggle position for the header.
  545. * @return {?}
  546. */
  547. function () {
  548. return this.panel.togglePosition;
  549. };
  550. /** Gets whether the expand indicator should be shown. */
  551. /**
  552. * Gets whether the expand indicator should be shown.
  553. * @return {?}
  554. */
  555. MatExpansionPanelHeader.prototype._showToggle = /**
  556. * Gets whether the expand indicator should be shown.
  557. * @return {?}
  558. */
  559. function () {
  560. return !this.panel.hideToggle && !this.panel.disabled;
  561. };
  562. /** Handle keydown event calling to toggle() if appropriate. */
  563. /**
  564. * Handle keydown event calling to toggle() if appropriate.
  565. * @param {?} event
  566. * @return {?}
  567. */
  568. MatExpansionPanelHeader.prototype._keydown = /**
  569. * Handle keydown event calling to toggle() if appropriate.
  570. * @param {?} event
  571. * @return {?}
  572. */
  573. function (event) {
  574. switch (event.keyCode) {
  575. // Toggle for space and enter keys.
  576. case SPACE:
  577. case ENTER:
  578. if (!hasModifierKey(event)) {
  579. event.preventDefault();
  580. this._toggle();
  581. }
  582. break;
  583. default:
  584. if (this.panel.accordion) {
  585. this.panel.accordion._handleHeaderKeydown(event);
  586. }
  587. return;
  588. }
  589. };
  590. /**
  591. * Focuses the panel header. Implemented as a part of `FocusableOption`.
  592. * @param origin Origin of the action that triggered the focus.
  593. * @docs-private
  594. */
  595. /**
  596. * Focuses the panel header. Implemented as a part of `FocusableOption`.
  597. * \@docs-private
  598. * @param {?=} origin Origin of the action that triggered the focus.
  599. * @param {?=} options
  600. * @return {?}
  601. */
  602. MatExpansionPanelHeader.prototype.focus = /**
  603. * Focuses the panel header. Implemented as a part of `FocusableOption`.
  604. * \@docs-private
  605. * @param {?=} origin Origin of the action that triggered the focus.
  606. * @param {?=} options
  607. * @return {?}
  608. */
  609. function (origin, options) {
  610. if (origin === void 0) { origin = 'program'; }
  611. this._focusMonitor.focusVia(this._element, origin, options);
  612. };
  613. /**
  614. * @return {?}
  615. */
  616. MatExpansionPanelHeader.prototype.ngOnDestroy = /**
  617. * @return {?}
  618. */
  619. function () {
  620. this._parentChangeSubscription.unsubscribe();
  621. this._focusMonitor.stopMonitoring(this._element);
  622. };
  623. MatExpansionPanelHeader.decorators = [
  624. { type: Component, args: [{selector: 'mat-expansion-panel-header',
  625. styles: [".mat-expansion-panel-header{display:flex;flex-direction:row;align-items:center;padding:0 24px;border-radius:inherit}.mat-expansion-panel-header:focus,.mat-expansion-panel-header:hover{outline:0}.mat-expansion-panel-header.mat-expanded:focus,.mat-expansion-panel-header.mat-expanded:hover{background:inherit}.mat-expansion-panel-header:not([aria-disabled=true]){cursor:pointer}.mat-expansion-panel-header.mat-expansion-toggle-indicator-before{flex-direction:row-reverse}.mat-expansion-panel-header.mat-expansion-toggle-indicator-before .mat-expansion-indicator{margin:0 16px 0 0}[dir=rtl] .mat-expansion-panel-header.mat-expansion-toggle-indicator-before .mat-expansion-indicator{margin:0 0 0 16px}.mat-content{display:flex;flex:1;flex-direction:row;overflow:hidden}.mat-expansion-panel-header-description,.mat-expansion-panel-header-title{display:flex;flex-grow:1;margin-right:16px}[dir=rtl] .mat-expansion-panel-header-description,[dir=rtl] .mat-expansion-panel-header-title{margin-right:0;margin-left:16px}.mat-expansion-panel-header-description{flex-grow:2}.mat-expansion-indicator::after{border-style:solid;border-width:0 2px 2px 0;content:'';display:inline-block;padding:3px;transform:rotate(45deg);vertical-align:middle}"],
  626. template: "<span class=\"mat-content\"><ng-content select=\"mat-panel-title\"></ng-content><ng-content select=\"mat-panel-description\"></ng-content><ng-content></ng-content></span><span [@indicatorRotate]=\"_getExpandedState()\" *ngIf=\"_showToggle()\" class=\"mat-expansion-indicator\"></span>",
  627. encapsulation: ViewEncapsulation.None,
  628. changeDetection: ChangeDetectionStrategy.OnPush,
  629. animations: [
  630. matExpansionAnimations.indicatorRotate,
  631. matExpansionAnimations.expansionHeaderHeight
  632. ],
  633. host: {
  634. 'class': 'mat-expansion-panel-header',
  635. 'role': 'button',
  636. '[attr.id]': 'panel._headerId',
  637. '[attr.tabindex]': 'disabled ? -1 : 0',
  638. '[attr.aria-controls]': '_getPanelId()',
  639. '[attr.aria-expanded]': '_isExpanded()',
  640. '[attr.aria-disabled]': 'panel.disabled',
  641. '[class.mat-expanded]': '_isExpanded()',
  642. '[class.mat-expansion-toggle-indicator-after]': "_getTogglePosition() === 'after'",
  643. '[class.mat-expansion-toggle-indicator-before]': "_getTogglePosition() === 'before'",
  644. '(click)': '_toggle()',
  645. '(keydown)': '_keydown($event)',
  646. '[@.disabled]': '_animationsDisabled',
  647. '(@expansionHeight.start)': '_animationStarted()',
  648. '[@expansionHeight]': "{\n value: _getExpandedState(),\n params: {\n collapsedHeight: collapsedHeight,\n expandedHeight: expandedHeight\n }\n }",
  649. },
  650. },] },
  651. ];
  652. /** @nocollapse */
  653. MatExpansionPanelHeader.ctorParameters = function () { return [
  654. { type: MatExpansionPanel, decorators: [{ type: Host }] },
  655. { type: ElementRef },
  656. { type: FocusMonitor },
  657. { type: ChangeDetectorRef },
  658. { type: undefined, decorators: [{ type: Inject, args: [MAT_EXPANSION_PANEL_DEFAULT_OPTIONS,] }, { type: Optional }] }
  659. ]; };
  660. MatExpansionPanelHeader.propDecorators = {
  661. expandedHeight: [{ type: Input }],
  662. collapsedHeight: [{ type: Input }]
  663. };
  664. return MatExpansionPanelHeader;
  665. }());
  666. /**
  667. * `<mat-panel-description>`
  668. *
  669. * This directive is to be used inside of the MatExpansionPanelHeader component.
  670. */
  671. var MatExpansionPanelDescription = /** @class */ (function () {
  672. function MatExpansionPanelDescription() {
  673. }
  674. MatExpansionPanelDescription.decorators = [
  675. { type: Directive, args: [{
  676. selector: 'mat-panel-description',
  677. host: {
  678. class: 'mat-expansion-panel-header-description'
  679. }
  680. },] },
  681. ];
  682. return MatExpansionPanelDescription;
  683. }());
  684. /**
  685. * `<mat-panel-title>`
  686. *
  687. * This directive is to be used inside of the MatExpansionPanelHeader component.
  688. */
  689. var MatExpansionPanelTitle = /** @class */ (function () {
  690. function MatExpansionPanelTitle() {
  691. }
  692. MatExpansionPanelTitle.decorators = [
  693. { type: Directive, args: [{
  694. selector: 'mat-panel-title',
  695. host: {
  696. class: 'mat-expansion-panel-header-title'
  697. }
  698. },] },
  699. ];
  700. return MatExpansionPanelTitle;
  701. }());
  702. /**
  703. * @fileoverview added by tsickle
  704. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  705. */
  706. /**
  707. * Directive for a Material Design Accordion.
  708. */
  709. var MatAccordion = /** @class */ (function (_super) {
  710. __extends(MatAccordion, _super);
  711. function MatAccordion() {
  712. var _this = _super !== null && _super.apply(this, arguments) || this;
  713. _this._hideToggle = false;
  714. /**
  715. * Display mode used for all expansion panels in the accordion. Currently two display
  716. * modes exist:
  717. * default - a gutter-like spacing is placed around any expanded panel, placing the expanded
  718. * panel at a different elevation from the rest of the accordion.
  719. * flat - no spacing is placed around expanded panels, showing all panels at the same
  720. * elevation.
  721. */
  722. _this.displayMode = 'default';
  723. /**
  724. * The position of the expansion indicator.
  725. */
  726. _this.togglePosition = 'after';
  727. return _this;
  728. }
  729. Object.defineProperty(MatAccordion.prototype, "hideToggle", {
  730. /** Whether the expansion indicator should be hidden. */
  731. get: /**
  732. * Whether the expansion indicator should be hidden.
  733. * @return {?}
  734. */
  735. function () { return this._hideToggle; },
  736. set: /**
  737. * @param {?} show
  738. * @return {?}
  739. */
  740. function (show) { this._hideToggle = coerceBooleanProperty(show); },
  741. enumerable: true,
  742. configurable: true
  743. });
  744. /**
  745. * @return {?}
  746. */
  747. MatAccordion.prototype.ngAfterContentInit = /**
  748. * @return {?}
  749. */
  750. function () {
  751. this._keyManager = new FocusKeyManager(this._headers).withWrap();
  752. };
  753. /** Handles keyboard events coming in from the panel headers. */
  754. /**
  755. * Handles keyboard events coming in from the panel headers.
  756. * @param {?} event
  757. * @return {?}
  758. */
  759. MatAccordion.prototype._handleHeaderKeydown = /**
  760. * Handles keyboard events coming in from the panel headers.
  761. * @param {?} event
  762. * @return {?}
  763. */
  764. function (event) {
  765. var keyCode = event.keyCode;
  766. /** @type {?} */
  767. var manager = this._keyManager;
  768. if (keyCode === HOME) {
  769. if (!hasModifierKey(event)) {
  770. manager.setFirstItemActive();
  771. event.preventDefault();
  772. }
  773. }
  774. else if (keyCode === END) {
  775. if (!hasModifierKey(event)) {
  776. manager.setLastItemActive();
  777. event.preventDefault();
  778. }
  779. }
  780. else {
  781. this._keyManager.onKeydown(event);
  782. }
  783. };
  784. /**
  785. * @param {?} header
  786. * @return {?}
  787. */
  788. MatAccordion.prototype._handleHeaderFocus = /**
  789. * @param {?} header
  790. * @return {?}
  791. */
  792. function (header) {
  793. this._keyManager.updateActiveItem(header);
  794. };
  795. MatAccordion.decorators = [
  796. { type: Directive, args: [{
  797. selector: 'mat-accordion',
  798. exportAs: 'matAccordion',
  799. inputs: ['multi'],
  800. providers: [{
  801. provide: MAT_ACCORDION,
  802. useExisting: MatAccordion
  803. }],
  804. host: {
  805. class: 'mat-accordion'
  806. }
  807. },] },
  808. ];
  809. MatAccordion.propDecorators = {
  810. _headers: [{ type: ContentChildren, args: [MatExpansionPanelHeader, { descendants: true },] }],
  811. hideToggle: [{ type: Input }],
  812. displayMode: [{ type: Input }],
  813. togglePosition: [{ type: Input }]
  814. };
  815. return MatAccordion;
  816. }(CdkAccordion));
  817. /**
  818. * @fileoverview added by tsickle
  819. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  820. */
  821. var MatExpansionModule = /** @class */ (function () {
  822. function MatExpansionModule() {
  823. }
  824. MatExpansionModule.decorators = [
  825. { type: NgModule, args: [{
  826. imports: [CommonModule, CdkAccordionModule, PortalModule],
  827. exports: [
  828. MatAccordion,
  829. MatExpansionPanel,
  830. MatExpansionPanelActionRow,
  831. MatExpansionPanelHeader,
  832. MatExpansionPanelTitle,
  833. MatExpansionPanelDescription,
  834. MatExpansionPanelContent,
  835. ],
  836. declarations: [
  837. MatAccordion,
  838. MatExpansionPanel,
  839. MatExpansionPanelActionRow,
  840. MatExpansionPanelHeader,
  841. MatExpansionPanelTitle,
  842. MatExpansionPanelDescription,
  843. MatExpansionPanelContent,
  844. ],
  845. },] },
  846. ];
  847. return MatExpansionModule;
  848. }());
  849. /**
  850. * @fileoverview added by tsickle
  851. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  852. */
  853. /**
  854. * @fileoverview added by tsickle
  855. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  856. */
  857. export { MatExpansionModule, MatAccordion, MAT_ACCORDION, MAT_EXPANSION_PANEL_DEFAULT_OPTIONS, MatExpansionPanel, MatExpansionPanelActionRow, MatExpansionPanelHeader, MatExpansionPanelDescription, MatExpansionPanelTitle, MatExpansionPanelContent, EXPANSION_PANEL_ANIMATION_TIMING, matExpansionAnimations };
  858. //# sourceMappingURL=expansion.es5.js.map