更改默认扩展面板箭头的箭头样式

时间:2017-10-04 02:34:14

标签: css angular angular-material angular-material2

我有一个角度扩展面板,如下所示。

enter image description here

但是我想将箭头的设计改为:

未展开:

enter image description here

展开:

enter image description here

如何?或者我可以用棱角分明的材料吗? 代码如下:

HTML:

<md-expansion-panel>
  <md-expansion-panel-header>
    <md-panel-title>
      Personal data
    </md-panel-title>
    <md-panel-description>
      Type your name and age
    </md-panel-description>
  </md-expansion-panel-header>

  <md-form-field>
    <input mdInput placeholder="First name">
  </md-form-field>

  <md-form-field>
    <input mdInput placeholder="Age">
  </md-form-field>
</md-expansion-panel>

TS:

import {Component} from '@angular/core';

/**
 * @title Basic expansion panel
 */
@Component({
  selector: 'expansion-overview-example',
  templateUrl: 'expansion-overview-example.html',
})
export class ExpansionOverviewExample {}

3 个答案:

答案 0 :(得分:13)

是的,这是可能的。为您的展开式面板提供参考ID,例如example并将hideToggle属性设置为true

<md-panel-description>中,您可以放置​​图标并使用面板的expanded属性来显示或隐藏相关图标。

  <md-expansion-panel  class="custom-header" hideToggle="true" #example>
    <md-expansion-panel-header>
      <md-panel-title>
        Personal data
      </md-panel-title>
      <md-panel-description>
        Type your name and age
        <md-icon *ngIf="!example.expanded">play_arrow</md-icon>
        <md-icon *ngIf="example.expanded">arrow_drop_down</md-icon>
      </md-panel-description>
    </md-expansion-panel-header>

    <md-form-field>
      <input mdInput placeholder="First name">
    </md-form-field>

    <md-form-field>
      <input mdInput placeholder="Age">
    </md-form-field>
  </md-expansion-panel>

要在图标和面板描述之间提供空间,请在component.css中添加以下类:

.custom-header .mat-expansion-panel-header-title, 
.custom-header .mat-expansion-panel-header-description {
  flex-basis: 0;
}

.custom-header .mat-expansion-panel-header-description {
  justify-content: space-between;
  align-items: center;
}

我使用过材料图标。您可以根据需要放置自定义图标。这是指向stackblitz demo的链接。

答案 1 :(得分:2)

扩展了@Faisal的答案,根据最新版本的角材料,我们将对材料组件使用mat前缀而不是md

  

角材料8.1.4

<mat-expansion-panel class="mb-15px" hideToggle="true" #xyz>
<mat-expansion-panel-header>
  <mat-panel-title class="font-weight-bold font-small">
    Info
  </mat-panel-title>
  <mat-panel-description>
    <mat-icon *ngIf="!xyz.expanded">play_arrow</mat-icon>
    <mat-icon *ngIf="xyz.expanded">arrow_drop_down</mat-icon>
  </mat-panel-description>
</mat-expansion-panel-header>
<mat-expansion-panel class="mb-15px" hideToggle="true" #xyz>

Stackblitz Demo

答案 2 :(得分:0)

另一个漂亮的解决方案.. 只需添加一个带有 fxFlex 的跨度

  <mat-panel-description>
       <span fxFlex></span>
       <img src="">
   </mat-panel-description>

不要忘记将 hideToggle 添加到 mat-expansion-panel

<mat-expansion-panel hideToggle>
相关问题