expansion.js 30 KB

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