MCPcopy Create free account
hub / github.com/angular/components / MatExpansionPanelHeader

Class MatExpansionPanelHeader

src/material/expansion/expansion-panel-header.ts:59–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 },
58})
59export class MatExpansionPanelHeader implements AfterViewInit, OnDestroy, FocusableOption {
60 panel = inject(MatExpansionPanel, {host: true});
61 private _element = inject(ElementRef);
62 private _focusMonitor = inject(FocusMonitor);
63 private _changeDetectorRef = inject(ChangeDetectorRef);
64
65 private _parentChangeSubscription = Subscription.EMPTY;
66
67 constructor() {
68 inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader);
69 const panel = this.panel;
70 const defaultOptions = inject<MatExpansionPanelDefaultOptions>(
71 MAT_EXPANSION_PANEL_DEFAULT_OPTIONS,
72 {optional: true},
73 );
74 const tabIndex = inject(new HostAttributeToken('tabindex'), {optional: true});
75
76 const accordionHideToggleChange = panel.accordion
77 ? panel.accordion._stateChanges.pipe(
78 filter(changes => !!(changes['hideToggle'] || changes['togglePosition'])),
79 )
80 : EMPTY;
81 this.tabIndex = parseInt(tabIndex || '') || 0;
82
83 // Since the toggle state depends on an @Input on the panel, we
84 // need to subscribe and trigger change detection manually.
85 this._parentChangeSubscription = merge(
86 panel.opened,
87 panel.closed,
88 accordionHideToggleChange,
89 panel._inputChanges.pipe(
90 filter(changes => {
91 return !!(changes['hideToggle'] || changes['disabled'] || changes['togglePosition']);
92 }),
93 ),
94 ).subscribe(() => this._changeDetectorRef.markForCheck());
95
96 // Avoids focus being lost if the panel contained the focused element and was closed.
97 panel.closed
98 .pipe(filter(() => panel._containsFocus()))
99 .subscribe(() => this._focusMonitor.focusVia(this._element, 'program'));
100
101 if (defaultOptions) {
102 this.expandedHeight = defaultOptions.expandedHeight;
103 this.collapsedHeight = defaultOptions.collapsedHeight;
104 }
105 }
106
107 /** Height of the header while the panel is expanded. */
108 @Input() expandedHeight!: string;
109
110 /** Height of the header while the panel is collapsed. */
111 @Input() collapsedHeight!: string;
112
113 /** Tab index of the header. */
114 @Input({
115 transform: (value: unknown) => (value == null ? 0 : numberAttribute(value)),
116 })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected