Ale*_*Sim 20 angular-material angular-material2 angular
所以我一直在尝试在我的Web应用程序开发中采用Materials Accordion.
然而,随着内容的增长,使标题扩大的麻烦有些麻烦.
我的标题预计将有相当多的行来提供摘要,而不仅仅是1个班轮.
如果我硬编码材质标题高度,它会导致动画干扰.
下面是一个示例代码
<mat-accordion [displayMode]="displayMode" [multi]="multi" class="mat-expansion-demo-width">
<mat-expansion-panel #panel1 [hideToggle]="hideToggle">
<mat-expansion-panel-header>Section 1</mat-expansion-panel-header>
<p>This is the content text that makes sense here.</p>
</mat-expansion-panel>
</mat-accordion>
Run Code Online (Sandbox Code Playgroud)
::ng-deep .mat-expansion-panel-header
{
height: 190px !important;
}
Run Code Online (Sandbox Code Playgroud)
如果我执行上述操作,则会设置高度,但展开和折叠的动画会很奇怪.
我该怎么办呢?
Fai*_*sal 53
你不必使用::ng-deep.您可以使用[collapsedHeight]和[expandedHeight]你的mat-expansion-panel-header.
<mat-accordion [displayMode]="displayMode" [multi]="multi" class="mat-expansion-demo-width">
<mat-expansion-panel #panel1 [hideToggle]="hideToggle">
<mat-expansion-panel-header [collapsedHeight]="'190px'" [expandedHeight]="'190px'">
Section 1
</mat-expansion-panel-header>
<p>This is the content text that makes sense here.</p>
</mat-expansion-panel>
</mat-accordion>
Run Code Online (Sandbox Code Playgroud)
链接到StackBlitz演示.
For*_*stG 15
截至今天使用Material 7.0.2,如果您希望标题遵循一些通用height:auto规则,则此修复高度可能不是您的解决方案.(例如,在响应情况下遵循标题中文本的大小)
在这些情况下,在css中定义自动高度要好得多:
mat-expansion-panel {
mat-expansion-panel-header {
height: auto!important;
}
}
Run Code Online (Sandbox Code Playgroud)
并定义
<mat-expansion-panel-header collapsedHeight="*" expandedHeight="*">
Run Code Online (Sandbox Code Playgroud)
如https://github.com/angular/material2/pull/9313中所述
Mat*_*tis 13
这就是对我有用的东西,没有 css 只是将 thowe 添加到 mat-expansion-panel-header
<mat-expansion-panel-header [collapsedHeight]="'auto'" [expandedHeight]="'auto'">
Run Code Online (Sandbox Code Playgroud)
添加通用选项/设置以设置应用程序中所有面板的高度:
MatExpansionPanelDefaultOptions
import { NgModule } from '@angular/core';
import { MAT_EXPANSION_PANEL_DEFAULT_OPTIONS } from '@angular/material';
@NgModule({
providers: [
{
provide: MAT_EXPANSION_PANEL_DEFAULT_OPTIONS,
useValue: {
hideToggle: true,
expandedHeight: '50px',
collapsedHeight: '50px'
}
}
]
})
export class AppMaterialModule {}
Run Code Online (Sandbox Code Playgroud)