expansion.mjs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. import { CdkAccordionItem, CdkAccordion, CdkAccordionModule } from '@angular/cdk/accordion';
  2. import * as i2 from '@angular/cdk/portal';
  3. import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
  4. import * as i3 from '@angular/common';
  5. import { DOCUMENT, CommonModule } from '@angular/common';
  6. import * as i0 from '@angular/core';
  7. import { InjectionToken, Directive, Inject, Optional, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, SkipSelf, Input, Output, ContentChild, ViewChild, Host, Attribute, QueryList, ContentChildren, NgModule } from '@angular/core';
  8. import { mixinTabIndex, MatCommonModule } from '@angular/material/core';
  9. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  10. import * as i2$1 from '@angular/cdk/a11y';
  11. import { FocusKeyManager } from '@angular/cdk/a11y';
  12. import { distinctUntilChanged, startWith, filter, take } from 'rxjs/operators';
  13. import { ENTER, hasModifierKey, SPACE } from '@angular/cdk/keycodes';
  14. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  15. import { Subject, Subscription, EMPTY, merge } from 'rxjs';
  16. import { trigger, state, style, transition, animate } from '@angular/animations';
  17. import * as i1 from '@angular/cdk/collections';
  18. /**
  19. * Token used to provide a `MatAccordion` to `MatExpansionPanel`.
  20. * Used primarily to avoid circular imports between `MatAccordion` and `MatExpansionPanel`.
  21. */
  22. const MAT_ACCORDION = new InjectionToken('MAT_ACCORDION');
  23. /** Time and timing curve for expansion panel animations. */
  24. // Note: Keep this in sync with the Sass variable for the panel header animation.
  25. const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,1)';
  26. /**
  27. * Animations used by the Material expansion panel.
  28. *
  29. * A bug in angular animation's `state` when ViewContainers are moved using ViewContainerRef.move()
  30. * causes the animation state of moved components to become `void` upon exit, and not update again
  31. * upon reentry into the DOM. This can lead a to situation for the expansion panel where the state
  32. * of the panel is `expanded` or `collapsed` but the animation state is `void`.
  33. *
  34. * To correctly handle animating to the next state, we animate between `void` and `collapsed` which
  35. * are defined to have the same styles. Since angular animates from the current styles to the
  36. * destination state's style definition, in situations where we are moving from `void`'s styles to
  37. * `collapsed` this acts a noop since no style values change.
  38. *
  39. * In the case where angular's animation state is out of sync with the expansion panel's state, the
  40. * expansion panel being `expanded` and angular animations being `void`, the animation from the
  41. * `expanded`'s effective styles (though in a `void` animation state) to the collapsed state will
  42. * occur as expected.
  43. *
  44. * Angular Bug: https://github.com/angular/angular/issues/18847
  45. *
  46. * @docs-private
  47. */
  48. const matExpansionAnimations = {
  49. /** Animation that rotates the indicator arrow. */
  50. indicatorRotate: trigger('indicatorRotate', [
  51. state('collapsed, void', style({ transform: 'rotate(0deg)' })),
  52. state('expanded', style({ transform: 'rotate(180deg)' })),
  53. transition('expanded <=> collapsed, void => collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  54. ]),
  55. /** Animation that expands and collapses the panel content. */
  56. bodyExpansion: trigger('bodyExpansion', [
  57. state('collapsed, void', style({ height: '0px', visibility: 'hidden' })),
  58. state('expanded', style({ height: '*', visibility: 'visible' })),
  59. transition('expanded <=> collapsed, void => collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
  60. ]),
  61. };
  62. /**
  63. * Token used to provide a `MatExpansionPanel` to `MatExpansionPanelContent`.
  64. * Used to avoid circular imports between `MatExpansionPanel` and `MatExpansionPanelContent`.
  65. */
  66. const MAT_EXPANSION_PANEL = new InjectionToken('MAT_EXPANSION_PANEL');
  67. /**
  68. * Expansion panel content that will be rendered lazily
  69. * after the panel is opened for the first time.
  70. */
  71. class MatExpansionPanelContent {
  72. constructor(_template, _expansionPanel) {
  73. this._template = _template;
  74. this._expansionPanel = _expansionPanel;
  75. }
  76. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelContent, deps: [{ token: i0.TemplateRef }, { token: MAT_EXPANSION_PANEL, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
  77. static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanelContent, selector: "ng-template[matExpansionPanelContent]", ngImport: i0 }); }
  78. }
  79. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelContent, decorators: [{
  80. type: Directive,
  81. args: [{
  82. selector: 'ng-template[matExpansionPanelContent]',
  83. }]
  84. }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: undefined, decorators: [{
  85. type: Inject,
  86. args: [MAT_EXPANSION_PANEL]
  87. }, {
  88. type: Optional
  89. }] }]; } });
  90. /** Counter for generating unique element ids. */
  91. let uniqueId = 0;
  92. /**
  93. * Injection token that can be used to configure the default
  94. * options for the expansion panel component.
  95. */
  96. const MAT_EXPANSION_PANEL_DEFAULT_OPTIONS = new InjectionToken('MAT_EXPANSION_PANEL_DEFAULT_OPTIONS');
  97. /**
  98. * This component can be used as a single element to show expandable content, or as one of
  99. * multiple children of an element with the MatAccordion directive attached.
  100. */
  101. class MatExpansionPanel extends CdkAccordionItem {
  102. /** Whether the toggle indicator should be hidden. */
  103. get hideToggle() {
  104. return this._hideToggle || (this.accordion && this.accordion.hideToggle);
  105. }
  106. set hideToggle(value) {
  107. this._hideToggle = coerceBooleanProperty(value);
  108. }
  109. /** The position of the expansion indicator. */
  110. get togglePosition() {
  111. return this._togglePosition || (this.accordion && this.accordion.togglePosition);
  112. }
  113. set togglePosition(value) {
  114. this._togglePosition = value;
  115. }
  116. constructor(accordion, _changeDetectorRef, _uniqueSelectionDispatcher, _viewContainerRef, _document, _animationMode, defaultOptions) {
  117. super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher);
  118. this._viewContainerRef = _viewContainerRef;
  119. this._animationMode = _animationMode;
  120. this._hideToggle = false;
  121. /** An event emitted after the body's expansion animation happens. */
  122. this.afterExpand = new EventEmitter();
  123. /** An event emitted after the body's collapse animation happens. */
  124. this.afterCollapse = new EventEmitter();
  125. /** Stream that emits for changes in `@Input` properties. */
  126. this._inputChanges = new Subject();
  127. /** ID for the associated header element. Used for a11y labelling. */
  128. this._headerId = `mat-expansion-panel-header-${uniqueId++}`;
  129. /** Stream of body animation done events. */
  130. this._bodyAnimationDone = new Subject();
  131. this.accordion = accordion;
  132. this._document = _document;
  133. // We need a Subject with distinctUntilChanged, because the `done` event
  134. // fires twice on some browsers. See https://github.com/angular/angular/issues/24084
  135. this._bodyAnimationDone
  136. .pipe(distinctUntilChanged((x, y) => {
  137. return x.fromState === y.fromState && x.toState === y.toState;
  138. }))
  139. .subscribe(event => {
  140. if (event.fromState !== 'void') {
  141. if (event.toState === 'expanded') {
  142. this.afterExpand.emit();
  143. }
  144. else if (event.toState === 'collapsed') {
  145. this.afterCollapse.emit();
  146. }
  147. }
  148. });
  149. if (defaultOptions) {
  150. this.hideToggle = defaultOptions.hideToggle;
  151. }
  152. }
  153. /** Determines whether the expansion panel should have spacing between it and its siblings. */
  154. _hasSpacing() {
  155. if (this.accordion) {
  156. return this.expanded && this.accordion.displayMode === 'default';
  157. }
  158. return false;
  159. }
  160. /** Gets the expanded state string. */
  161. _getExpandedState() {
  162. return this.expanded ? 'expanded' : 'collapsed';
  163. }
  164. /** Toggles the expanded state of the expansion panel. */
  165. toggle() {
  166. this.expanded = !this.expanded;
  167. }
  168. /** Sets the expanded state of the expansion panel to false. */
  169. close() {
  170. this.expanded = false;
  171. }
  172. /** Sets the expanded state of the expansion panel to true. */
  173. open() {
  174. this.expanded = true;
  175. }
  176. ngAfterContentInit() {
  177. if (this._lazyContent && this._lazyContent._expansionPanel === this) {
  178. // Render the content as soon as the panel becomes open.
  179. this.opened
  180. .pipe(startWith(null), filter(() => this.expanded && !this._portal), take(1))
  181. .subscribe(() => {
  182. this._portal = new TemplatePortal(this._lazyContent._template, this._viewContainerRef);
  183. });
  184. }
  185. }
  186. ngOnChanges(changes) {
  187. this._inputChanges.next(changes);
  188. }
  189. ngOnDestroy() {
  190. super.ngOnDestroy();
  191. this._bodyAnimationDone.complete();
  192. this._inputChanges.complete();
  193. }
  194. /** Checks whether the expansion panel's content contains the currently-focused element. */
  195. _containsFocus() {
  196. if (this._body) {
  197. const focusedElement = this._document.activeElement;
  198. const bodyElement = this._body.nativeElement;
  199. return focusedElement === bodyElement || bodyElement.contains(focusedElement);
  200. }
  201. return false;
  202. }
  203. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanel, deps: [{ token: MAT_ACCORDION, optional: true, skipSelf: true }, { token: i0.ChangeDetectorRef }, { token: i1.UniqueSelectionDispatcher }, { token: i0.ViewContainerRef }, { token: DOCUMENT }, { token: ANIMATION_MODULE_TYPE, optional: true }, { token: MAT_EXPANSION_PANEL_DEFAULT_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
  204. static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanel, selector: "mat-expansion-panel", inputs: { disabled: "disabled", expanded: "expanded", hideToggle: "hideToggle", togglePosition: "togglePosition" }, outputs: { opened: "opened", closed: "closed", expandedChange: "expandedChange", afterExpand: "afterExpand", afterCollapse: "afterCollapse" }, host: { properties: { "class.mat-expanded": "expanded", "class._mat-animation-noopable": "_animationMode === \"NoopAnimations\"", "class.mat-expansion-panel-spacing": "_hasSpacing()" }, classAttribute: "mat-expansion-panel" }, providers: [
  205. // Provide MatAccordion as undefined to prevent nested expansion panels from registering
  206. // to the same accordion.
  207. { provide: MAT_ACCORDION, useValue: undefined },
  208. { provide: MAT_EXPANSION_PANEL, useExisting: MatExpansionPanel },
  209. ], queries: [{ propertyName: "_lazyContent", first: true, predicate: MatExpansionPanelContent, descendants: true }], viewQueries: [{ propertyName: "_body", first: true, predicate: ["body"], descendants: true }], exportAs: ["matExpansionPanel"], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ng-content select=\"mat-expansion-panel-header\"></ng-content>\n<div class=\"mat-expansion-panel-content\"\n role=\"region\"\n [@bodyExpansion]=\"_getExpandedState()\"\n (@bodyExpansion.done)=\"_bodyAnimationDone.next($event)\"\n [attr.aria-labelledby]=\"_headerId\"\n [id]=\"id\"\n #body>\n <div class=\"mat-expansion-panel-body\">\n <ng-content></ng-content>\n <ng-template [cdkPortalOutlet]=\"_portal\"></ng-template>\n </div>\n <ng-content select=\"mat-action-row\"></ng-content>\n</div>\n", styles: [".mat-expansion-panel{box-sizing:content-box;display:block;margin:0;border-radius:4px;overflow:hidden;transition:margin 225ms cubic-bezier(0.4, 0, 0.2, 1),box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);position:relative}.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}.cdk-high-contrast-active .mat-expansion-panel{outline:solid 1px}.mat-expansion-panel.ng-animate-disabled,.ng-animate-disabled .mat-expansion-panel,.mat-expansion-panel._mat-animation-noopable{transition:none}.mat-expansion-panel-content{display:flex;flex-direction:column;overflow:visible}.mat-expansion-panel-content[style*=\"visibility: hidden\"] *{visibility:hidden !important}.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 .mat-button-base,.mat-action-row .mat-mdc-button-base{margin-left:8px}[dir=rtl] .mat-action-row .mat-button-base,[dir=rtl] .mat-action-row .mat-mdc-button-base{margin-left:0;margin-right:8px}"], dependencies: [{ kind: "directive", type: i2.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }], animations: [matExpansionAnimations.bodyExpansion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
  210. }
  211. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanel, decorators: [{
  212. type: Component,
  213. args: [{ selector: 'mat-expansion-panel', exportAs: 'matExpansionPanel', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, inputs: ['disabled', 'expanded'], outputs: ['opened', 'closed', 'expandedChange'], animations: [matExpansionAnimations.bodyExpansion], providers: [
  214. // Provide MatAccordion as undefined to prevent nested expansion panels from registering
  215. // to the same accordion.
  216. { provide: MAT_ACCORDION, useValue: undefined },
  217. { provide: MAT_EXPANSION_PANEL, useExisting: MatExpansionPanel },
  218. ], host: {
  219. 'class': 'mat-expansion-panel',
  220. '[class.mat-expanded]': 'expanded',
  221. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  222. '[class.mat-expansion-panel-spacing]': '_hasSpacing()',
  223. }, template: "<ng-content select=\"mat-expansion-panel-header\"></ng-content>\n<div class=\"mat-expansion-panel-content\"\n role=\"region\"\n [@bodyExpansion]=\"_getExpandedState()\"\n (@bodyExpansion.done)=\"_bodyAnimationDone.next($event)\"\n [attr.aria-labelledby]=\"_headerId\"\n [id]=\"id\"\n #body>\n <div class=\"mat-expansion-panel-body\">\n <ng-content></ng-content>\n <ng-template [cdkPortalOutlet]=\"_portal\"></ng-template>\n </div>\n <ng-content select=\"mat-action-row\"></ng-content>\n</div>\n", styles: [".mat-expansion-panel{box-sizing:content-box;display:block;margin:0;border-radius:4px;overflow:hidden;transition:margin 225ms cubic-bezier(0.4, 0, 0.2, 1),box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);position:relative}.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}.cdk-high-contrast-active .mat-expansion-panel{outline:solid 1px}.mat-expansion-panel.ng-animate-disabled,.ng-animate-disabled .mat-expansion-panel,.mat-expansion-panel._mat-animation-noopable{transition:none}.mat-expansion-panel-content{display:flex;flex-direction:column;overflow:visible}.mat-expansion-panel-content[style*=\"visibility: hidden\"] *{visibility:hidden !important}.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 .mat-button-base,.mat-action-row .mat-mdc-button-base{margin-left:8px}[dir=rtl] .mat-action-row .mat-button-base,[dir=rtl] .mat-action-row .mat-mdc-button-base{margin-left:0;margin-right:8px}"] }]
  224. }], ctorParameters: function () { return [{ type: undefined, decorators: [{
  225. type: Optional
  226. }, {
  227. type: SkipSelf
  228. }, {
  229. type: Inject,
  230. args: [MAT_ACCORDION]
  231. }] }, { type: i0.ChangeDetectorRef }, { type: i1.UniqueSelectionDispatcher }, { type: i0.ViewContainerRef }, { type: undefined, decorators: [{
  232. type: Inject,
  233. args: [DOCUMENT]
  234. }] }, { type: undefined, decorators: [{
  235. type: Optional
  236. }, {
  237. type: Inject,
  238. args: [ANIMATION_MODULE_TYPE]
  239. }] }, { type: undefined, decorators: [{
  240. type: Inject,
  241. args: [MAT_EXPANSION_PANEL_DEFAULT_OPTIONS]
  242. }, {
  243. type: Optional
  244. }] }]; }, propDecorators: { hideToggle: [{
  245. type: Input
  246. }], togglePosition: [{
  247. type: Input
  248. }], afterExpand: [{
  249. type: Output
  250. }], afterCollapse: [{
  251. type: Output
  252. }], _lazyContent: [{
  253. type: ContentChild,
  254. args: [MatExpansionPanelContent]
  255. }], _body: [{
  256. type: ViewChild,
  257. args: ['body']
  258. }] } });
  259. /**
  260. * Actions of a `<mat-expansion-panel>`.
  261. */
  262. class MatExpansionPanelActionRow {
  263. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelActionRow, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
  264. static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanelActionRow, selector: "mat-action-row", host: { classAttribute: "mat-action-row" }, ngImport: i0 }); }
  265. }
  266. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelActionRow, decorators: [{
  267. type: Directive,
  268. args: [{
  269. selector: 'mat-action-row',
  270. host: {
  271. class: 'mat-action-row',
  272. },
  273. }]
  274. }] });
  275. // Boilerplate for applying mixins to MatExpansionPanelHeader.
  276. /** @docs-private */
  277. class MatExpansionPanelHeaderBase {
  278. }
  279. const _MatExpansionPanelHeaderMixinBase = mixinTabIndex(MatExpansionPanelHeaderBase);
  280. /**
  281. * Header element of a `<mat-expansion-panel>`.
  282. */
  283. class MatExpansionPanelHeader extends _MatExpansionPanelHeaderMixinBase {
  284. constructor(panel, _element, _focusMonitor, _changeDetectorRef, defaultOptions, _animationMode, tabIndex) {
  285. super();
  286. this.panel = panel;
  287. this._element = _element;
  288. this._focusMonitor = _focusMonitor;
  289. this._changeDetectorRef = _changeDetectorRef;
  290. this._animationMode = _animationMode;
  291. this._parentChangeSubscription = Subscription.EMPTY;
  292. const accordionHideToggleChange = panel.accordion
  293. ? panel.accordion._stateChanges.pipe(filter(changes => !!(changes['hideToggle'] || changes['togglePosition'])))
  294. : EMPTY;
  295. this.tabIndex = parseInt(tabIndex || '') || 0;
  296. // Since the toggle state depends on an @Input on the panel, we
  297. // need to subscribe and trigger change detection manually.
  298. this._parentChangeSubscription = merge(panel.opened, panel.closed, accordionHideToggleChange, panel._inputChanges.pipe(filter(changes => {
  299. return !!(changes['hideToggle'] || changes['disabled'] || changes['togglePosition']);
  300. }))).subscribe(() => this._changeDetectorRef.markForCheck());
  301. // Avoids focus being lost if the panel contained the focused element and was closed.
  302. panel.closed
  303. .pipe(filter(() => panel._containsFocus()))
  304. .subscribe(() => _focusMonitor.focusVia(_element, 'program'));
  305. if (defaultOptions) {
  306. this.expandedHeight = defaultOptions.expandedHeight;
  307. this.collapsedHeight = defaultOptions.collapsedHeight;
  308. }
  309. }
  310. /**
  311. * Whether the associated panel is disabled. Implemented as a part of `FocusableOption`.
  312. * @docs-private
  313. */
  314. get disabled() {
  315. return this.panel.disabled;
  316. }
  317. /** Toggles the expanded state of the panel. */
  318. _toggle() {
  319. if (!this.disabled) {
  320. this.panel.toggle();
  321. }
  322. }
  323. /** Gets whether the panel is expanded. */
  324. _isExpanded() {
  325. return this.panel.expanded;
  326. }
  327. /** Gets the expanded state string of the panel. */
  328. _getExpandedState() {
  329. return this.panel._getExpandedState();
  330. }
  331. /** Gets the panel id. */
  332. _getPanelId() {
  333. return this.panel.id;
  334. }
  335. /** Gets the toggle position for the header. */
  336. _getTogglePosition() {
  337. return this.panel.togglePosition;
  338. }
  339. /** Gets whether the expand indicator should be shown. */
  340. _showToggle() {
  341. return !this.panel.hideToggle && !this.panel.disabled;
  342. }
  343. /**
  344. * Gets the current height of the header. Null if no custom height has been
  345. * specified, and if the default height from the stylesheet should be used.
  346. */
  347. _getHeaderHeight() {
  348. const isExpanded = this._isExpanded();
  349. if (isExpanded && this.expandedHeight) {
  350. return this.expandedHeight;
  351. }
  352. else if (!isExpanded && this.collapsedHeight) {
  353. return this.collapsedHeight;
  354. }
  355. return null;
  356. }
  357. /** Handle keydown event calling to toggle() if appropriate. */
  358. _keydown(event) {
  359. switch (event.keyCode) {
  360. // Toggle for space and enter keys.
  361. case SPACE:
  362. case ENTER:
  363. if (!hasModifierKey(event)) {
  364. event.preventDefault();
  365. this._toggle();
  366. }
  367. break;
  368. default:
  369. if (this.panel.accordion) {
  370. this.panel.accordion._handleHeaderKeydown(event);
  371. }
  372. return;
  373. }
  374. }
  375. /**
  376. * Focuses the panel header. Implemented as a part of `FocusableOption`.
  377. * @param origin Origin of the action that triggered the focus.
  378. * @docs-private
  379. */
  380. focus(origin, options) {
  381. if (origin) {
  382. this._focusMonitor.focusVia(this._element, origin, options);
  383. }
  384. else {
  385. this._element.nativeElement.focus(options);
  386. }
  387. }
  388. ngAfterViewInit() {
  389. this._focusMonitor.monitor(this._element).subscribe(origin => {
  390. if (origin && this.panel.accordion) {
  391. this.panel.accordion._handleHeaderFocus(this);
  392. }
  393. });
  394. }
  395. ngOnDestroy() {
  396. this._parentChangeSubscription.unsubscribe();
  397. this._focusMonitor.stopMonitoring(this._element);
  398. }
  399. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelHeader, deps: [{ token: MatExpansionPanel, host: true }, { token: i0.ElementRef }, { token: i2$1.FocusMonitor }, { token: i0.ChangeDetectorRef }, { token: MAT_EXPANSION_PANEL_DEFAULT_OPTIONS, optional: true }, { token: ANIMATION_MODULE_TYPE, optional: true }, { token: 'tabindex', attribute: true }], target: i0.ɵɵFactoryTarget.Component }); }
  400. static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanelHeader, selector: "mat-expansion-panel-header", inputs: { tabIndex: "tabIndex", expandedHeight: "expandedHeight", collapsedHeight: "collapsedHeight" }, host: { attributes: { "role": "button" }, listeners: { "click": "_toggle()", "keydown": "_keydown($event)" }, properties: { "attr.id": "panel._headerId", "attr.tabindex": "tabIndex", "attr.aria-controls": "_getPanelId()", "attr.aria-expanded": "_isExpanded()", "attr.aria-disabled": "panel.disabled", "class.mat-expanded": "_isExpanded()", "class.mat-expansion-toggle-indicator-after": "_getTogglePosition() === 'after'", "class.mat-expansion-toggle-indicator-before": "_getTogglePosition() === 'before'", "class._mat-animation-noopable": "_animationMode === \"NoopAnimations\"", "style.height": "_getHeaderHeight()" }, classAttribute: "mat-expansion-panel-header mat-focus-indicator" }, usesInheritance: true, ngImport: i0, template: "<span class=\"mat-content\" [class.mat-content-hide-toggle]=\"!_showToggle()\">\n <ng-content select=\"mat-panel-title\"></ng-content>\n <ng-content select=\"mat-panel-description\"></ng-content>\n <ng-content></ng-content>\n</span>\n<span [@indicatorRotate]=\"_getExpandedState()\" *ngIf=\"_showToggle()\"\n class=\"mat-expansion-indicator\"></span>\n", styles: [".mat-expansion-panel-header{display:flex;flex-direction:row;align-items:center;padding:0 24px;border-radius:inherit;transition:height 225ms cubic-bezier(0.4, 0, 0.2, 1)}.mat-expansion-panel-header._mat-animation-noopable{transition:none}.mat-expansion-panel-header:focus,.mat-expansion-panel-header:hover{outline:none}.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-content.mat-content-hide-toggle{margin-right:8px}[dir=rtl] .mat-content.mat-content-hide-toggle{margin-right:0;margin-left:8px}.mat-expansion-toggle-indicator-before .mat-content.mat-content-hide-toggle{margin-left:24px;margin-right:0}[dir=rtl] .mat-expansion-toggle-indicator-before .mat-content.mat-content-hide-toggle{margin-right:24px;margin-left:0}.mat-expansion-panel-header-title,.mat-expansion-panel-header-description{display:flex;flex-grow:1;flex-basis:0;margin-right:16px;align-items:center}[dir=rtl] .mat-expansion-panel-header-title,[dir=rtl] .mat-expansion-panel-header-description{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}.cdk-high-contrast-active .mat-expansion-panel-content{border-top:1px solid;border-top-left-radius:0;border-top-right-radius:0}"], dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], animations: [matExpansionAnimations.indicatorRotate], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
  401. }
  402. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelHeader, decorators: [{
  403. type: Component,
  404. args: [{ selector: 'mat-expansion-panel-header', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, inputs: ['tabIndex'], animations: [matExpansionAnimations.indicatorRotate], host: {
  405. 'class': 'mat-expansion-panel-header mat-focus-indicator',
  406. 'role': 'button',
  407. '[attr.id]': 'panel._headerId',
  408. '[attr.tabindex]': 'tabIndex',
  409. '[attr.aria-controls]': '_getPanelId()',
  410. '[attr.aria-expanded]': '_isExpanded()',
  411. '[attr.aria-disabled]': 'panel.disabled',
  412. '[class.mat-expanded]': '_isExpanded()',
  413. '[class.mat-expansion-toggle-indicator-after]': `_getTogglePosition() === 'after'`,
  414. '[class.mat-expansion-toggle-indicator-before]': `_getTogglePosition() === 'before'`,
  415. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  416. '[style.height]': '_getHeaderHeight()',
  417. '(click)': '_toggle()',
  418. '(keydown)': '_keydown($event)',
  419. }, template: "<span class=\"mat-content\" [class.mat-content-hide-toggle]=\"!_showToggle()\">\n <ng-content select=\"mat-panel-title\"></ng-content>\n <ng-content select=\"mat-panel-description\"></ng-content>\n <ng-content></ng-content>\n</span>\n<span [@indicatorRotate]=\"_getExpandedState()\" *ngIf=\"_showToggle()\"\n class=\"mat-expansion-indicator\"></span>\n", styles: [".mat-expansion-panel-header{display:flex;flex-direction:row;align-items:center;padding:0 24px;border-radius:inherit;transition:height 225ms cubic-bezier(0.4, 0, 0.2, 1)}.mat-expansion-panel-header._mat-animation-noopable{transition:none}.mat-expansion-panel-header:focus,.mat-expansion-panel-header:hover{outline:none}.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-content.mat-content-hide-toggle{margin-right:8px}[dir=rtl] .mat-content.mat-content-hide-toggle{margin-right:0;margin-left:8px}.mat-expansion-toggle-indicator-before .mat-content.mat-content-hide-toggle{margin-left:24px;margin-right:0}[dir=rtl] .mat-expansion-toggle-indicator-before .mat-content.mat-content-hide-toggle{margin-right:24px;margin-left:0}.mat-expansion-panel-header-title,.mat-expansion-panel-header-description{display:flex;flex-grow:1;flex-basis:0;margin-right:16px;align-items:center}[dir=rtl] .mat-expansion-panel-header-title,[dir=rtl] .mat-expansion-panel-header-description{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}.cdk-high-contrast-active .mat-expansion-panel-content{border-top:1px solid;border-top-left-radius:0;border-top-right-radius:0}"] }]
  420. }], ctorParameters: function () { return [{ type: MatExpansionPanel, decorators: [{
  421. type: Host
  422. }] }, { type: i0.ElementRef }, { type: i2$1.FocusMonitor }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
  423. type: Inject,
  424. args: [MAT_EXPANSION_PANEL_DEFAULT_OPTIONS]
  425. }, {
  426. type: Optional
  427. }] }, { type: undefined, decorators: [{
  428. type: Optional
  429. }, {
  430. type: Inject,
  431. args: [ANIMATION_MODULE_TYPE]
  432. }] }, { type: undefined, decorators: [{
  433. type: Attribute,
  434. args: ['tabindex']
  435. }] }]; }, propDecorators: { expandedHeight: [{
  436. type: Input
  437. }], collapsedHeight: [{
  438. type: Input
  439. }] } });
  440. /**
  441. * Description element of a `<mat-expansion-panel-header>`.
  442. */
  443. class MatExpansionPanelDescription {
  444. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
  445. static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanelDescription, selector: "mat-panel-description", host: { classAttribute: "mat-expansion-panel-header-description" }, ngImport: i0 }); }
  446. }
  447. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelDescription, decorators: [{
  448. type: Directive,
  449. args: [{
  450. selector: 'mat-panel-description',
  451. host: {
  452. class: 'mat-expansion-panel-header-description',
  453. },
  454. }]
  455. }] });
  456. /**
  457. * Title element of a `<mat-expansion-panel-header>`.
  458. */
  459. class MatExpansionPanelTitle {
  460. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelTitle, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
  461. static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: MatExpansionPanelTitle, selector: "mat-panel-title", host: { classAttribute: "mat-expansion-panel-header-title" }, ngImport: i0 }); }
  462. }
  463. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionPanelTitle, decorators: [{
  464. type: Directive,
  465. args: [{
  466. selector: 'mat-panel-title',
  467. host: {
  468. class: 'mat-expansion-panel-header-title',
  469. },
  470. }]
  471. }] });
  472. /**
  473. * Directive for a Material Design Accordion.
  474. */
  475. class MatAccordion extends CdkAccordion {
  476. constructor() {
  477. super(...arguments);
  478. /** Headers belonging to this accordion. */
  479. this._ownHeaders = new QueryList();
  480. this._hideToggle = false;
  481. /**
  482. * Display mode used for all expansion panels in the accordion. Currently two display
  483. * modes exist:
  484. * default - a gutter-like spacing is placed around any expanded panel, placing the expanded
  485. * panel at a different elevation from the rest of the accordion.
  486. * flat - no spacing is placed around expanded panels, showing all panels at the same
  487. * elevation.
  488. */
  489. this.displayMode = 'default';
  490. /** The position of the expansion indicator. */
  491. this.togglePosition = 'after';
  492. }
  493. /** Whether the expansion indicator should be hidden. */
  494. get hideToggle() {
  495. return this._hideToggle;
  496. }
  497. set hideToggle(show) {
  498. this._hideToggle = coerceBooleanProperty(show);
  499. }
  500. ngAfterContentInit() {
  501. this._headers.changes
  502. .pipe(startWith(this._headers))
  503. .subscribe((headers) => {
  504. this._ownHeaders.reset(headers.filter(header => header.panel.accordion === this));
  505. this._ownHeaders.notifyOnChanges();
  506. });
  507. this._keyManager = new FocusKeyManager(this._ownHeaders).withWrap().withHomeAndEnd();
  508. }
  509. /** Handles keyboard events coming in from the panel headers. */
  510. _handleHeaderKeydown(event) {
  511. this._keyManager.onKeydown(event);
  512. }
  513. _handleHeaderFocus(header) {
  514. this._keyManager.updateActiveItem(header);
  515. }
  516. ngOnDestroy() {
  517. super.ngOnDestroy();
  518. this._keyManager?.destroy();
  519. this._ownHeaders.destroy();
  520. }
  521. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatAccordion, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
  522. static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: MatAccordion, selector: "mat-accordion", inputs: { multi: "multi", hideToggle: "hideToggle", displayMode: "displayMode", togglePosition: "togglePosition" }, host: { properties: { "class.mat-accordion-multi": "this.multi" }, classAttribute: "mat-accordion" }, providers: [
  523. {
  524. provide: MAT_ACCORDION,
  525. useExisting: MatAccordion,
  526. },
  527. ], queries: [{ propertyName: "_headers", predicate: MatExpansionPanelHeader, descendants: true }], exportAs: ["matAccordion"], usesInheritance: true, ngImport: i0 }); }
  528. }
  529. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatAccordion, decorators: [{
  530. type: Directive,
  531. args: [{
  532. selector: 'mat-accordion',
  533. exportAs: 'matAccordion',
  534. inputs: ['multi'],
  535. providers: [
  536. {
  537. provide: MAT_ACCORDION,
  538. useExisting: MatAccordion,
  539. },
  540. ],
  541. host: {
  542. class: 'mat-accordion',
  543. // Class binding which is only used by the test harness as there is no other
  544. // way for the harness to detect if multiple panel support is enabled.
  545. '[class.mat-accordion-multi]': 'this.multi',
  546. },
  547. }]
  548. }], propDecorators: { _headers: [{
  549. type: ContentChildren,
  550. args: [MatExpansionPanelHeader, { descendants: true }]
  551. }], hideToggle: [{
  552. type: Input
  553. }], displayMode: [{
  554. type: Input
  555. }], togglePosition: [{
  556. type: Input
  557. }] } });
  558. class MatExpansionModule {
  559. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
  560. static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionModule, declarations: [MatAccordion,
  561. MatExpansionPanel,
  562. MatExpansionPanelActionRow,
  563. MatExpansionPanelHeader,
  564. MatExpansionPanelTitle,
  565. MatExpansionPanelDescription,
  566. MatExpansionPanelContent], imports: [CommonModule, MatCommonModule, CdkAccordionModule, PortalModule], exports: [MatAccordion,
  567. MatExpansionPanel,
  568. MatExpansionPanelActionRow,
  569. MatExpansionPanelHeader,
  570. MatExpansionPanelTitle,
  571. MatExpansionPanelDescription,
  572. MatExpansionPanelContent] }); }
  573. static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionModule, imports: [CommonModule, MatCommonModule, CdkAccordionModule, PortalModule] }); }
  574. }
  575. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatExpansionModule, decorators: [{
  576. type: NgModule,
  577. args: [{
  578. imports: [CommonModule, MatCommonModule, CdkAccordionModule, PortalModule],
  579. exports: [
  580. MatAccordion,
  581. MatExpansionPanel,
  582. MatExpansionPanelActionRow,
  583. MatExpansionPanelHeader,
  584. MatExpansionPanelTitle,
  585. MatExpansionPanelDescription,
  586. MatExpansionPanelContent,
  587. ],
  588. declarations: [
  589. MatAccordion,
  590. MatExpansionPanel,
  591. MatExpansionPanelActionRow,
  592. MatExpansionPanelHeader,
  593. MatExpansionPanelTitle,
  594. MatExpansionPanelDescription,
  595. MatExpansionPanelContent,
  596. ],
  597. }]
  598. }] });
  599. /**
  600. * Generated bundle index. Do not edit.
  601. */
  602. export { EXPANSION_PANEL_ANIMATION_TIMING, MAT_ACCORDION, MAT_EXPANSION_PANEL, MAT_EXPANSION_PANEL_DEFAULT_OPTIONS, MatAccordion, MatExpansionModule, MatExpansionPanel, MatExpansionPanelActionRow, MatExpansionPanelContent, MatExpansionPanelDescription, MatExpansionPanelHeader, MatExpansionPanelTitle, matExpansionAnimations };
  603. //# sourceMappingURL=expansion.mjs.map