【问题标题】:Mat-Stepper - change specific steps to just dotsMat-Stepper - 将特定步骤更改为仅点
【发布时间】:2019-04-22 23:39:03
【问题描述】:

我看过这篇关于如何删除标题的帖子 Remove the Material Stepper header

但我在特定步骤中想要的只是在显示数字的跨度上不显示任何内容。

隐藏步进器的内部:

<span class="mat-step-icon-content ng-star-inserted">1</span>

我尝试使用 id 和 .span:after 或仅显示 none 的 .span,但没有运气..

#importer > .span{
  display:none;
}

这个可行,但我不希望它一起消失.. 只是数字和特定步骤..

::ng-deep #importer > .mat-horizontal-stepper-header-container {
  display: none !important;
} 

更新


import {
  Component,
  OnInit,
  ViewChild,
  ChangeDetectorRef
} from '@angular/core';
import {
  FormBuilder,
  FormGroup,
  Validators
} from '@angular/forms';
import {
  Entity
} from '../../models/entity';
import {
  EntityComponent
} from '../../entity/entity/entity/entity.component';
import {
  MatStepper
} from '@angular/material';
import {
  stepperActions
} from '../../models/stepper-actions';

@Component({
  selector: 'stepper',
  templateUrl: './stepper.component.html',
  styleUrls: ['./stepper.component.scss']
})
export class StepperComponent implements OnInit {
  isLinear = false;
  steps = new Array(13);

  constructor(private cd: ChangeDetectorRef) {}

  ngOnInit() {
    this.cd.detectChanges();
  }

}
@mixin hide-option($index, $label: '') {
  mat-step-header:nth-of-type(#{$index}) {
    .mat-step-icon-not-touched span,
    .mat-step-icon span,
    .mat-step-icon-not-touched .mat-icon,
    .mat-step-icon .mat-icon {
      display: none;
    }
    @if ($label=='') {
      .mat-step-icon {
        height: 5px !important;
        width: 5px !important;
      }
    }
    .mat-step-icon-not-touched:after,
    .mat-step-icon:after {
      content: $label;
      position: absolute;
      left: 8px;
      top: 3px;
    }
  }
}

:host /deep/ {
  mat-step-header .mat-step-label {
    overflow: visible;
  }
  @include hide-option(1, '1');
  @include hide-option(2);
  @include hide-option(3);
  @include hide-option(4);
  @include hide-option(5, '2');
  @include hide-option(6);
  @include hide-option(7);
  @include hide-option(8);
  @include hide-option(9, '3');
  @include hide-option(10, '4');
  @include hide-option(11);
  @include hide-option(12, '5');
  @include hide-option(13, '6');
}
<div class="teal-theme">
  <mat-horizontal-stepper [linear]="true" #stepper>
    <mat-step *ngFor="let i of steps" [stepControl]="i.childForm">
      <cby-step #i [stepper]='stepper'></cby-step>
    </mat-step>
  </mat-horizontal-stepper>
</div>

import {
  Component,
  OnInit,
  Input,
  Output,
  EventEmitter
} from '@angular/core';
import {
  MatStepper
} from '@angular/material';
import {
  FormGroup,
  FormBuilder
} from '@angular/forms';



@Component({
  selector: 'cby-step',
  templateUrl: './cby-step.component.html',
  styleUrls: ['./cby-step.component.scss']
})
export class CbyStepComponent implements OnInit {
  @Input() stepper: MatStepper;
  public childForm: FormGroup;
  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    this.childForm = this.fb.group({
      id: [0, '']
    });
  }

  previous() {
    this.updateForm();
    this.stepper.previous();
  }

  next() {
    this.updateForm();
    this.stepper.next();
  }

  updateForm() {
    this.childForm.controls['id'].setValue(this.stepper.selectedIndex);
    console.log(this.childForm.controls['id'].value);
  }

}
<p>
  {{stepper.selectedIndex}} step works!
</p>
<button mat-button (click)="previous()">Back</button>
<button mat-button (click)="next()">Next</button>

看看它是如何工作的 https://drive.google.com/file/d/1ScbvJZdwQFUIuBggYe8D0jzEdgjGqLU-/view

问题:

1) 步进器的响应性;

2)正确的样式只有经过特定的stepper步骤后才能正确

【问题讨论】:

  • 作为一个快速元注释,请在使用前阅读标签说明。 【设计】标签is currently in the process of being deleted,以后不要再使用了。
  • 此样式将隐藏所有数字在 mat-step ::ng-deep .mat-step-icon-content { display: none !important; }。您隐藏特定步骤编号的标准是什么?
  • 正如你在图片中看到的 - 我有 12 个步骤,其中只有 6 个需要数字,而不是一个接一个.. 含义 - 第一个表格,然后每个表格的点,然后是第 4 个的下一个数字通过图片形成..等
  • 我能以某种方式将你写的内容与计数元素结合起来,如下所述:stackoverflow.com/questions/8720931/…
  • 我也看到了@Teddy Sterne 的这个答案,但它似乎改变了所有标题,而我们需要专门将其更改为内部逻辑stackoverflow.com/questions/49560728/…

标签: css angular angular-material material-design


【解决方案1】:

您将无法通过使用类来做到这一点,因此它不能是动态的。如果这不是问题,那么我建议使用 SASS mixin 来创建每个标题项所需的样式。示例:

Demo

@mixin hide-option($index, $label: '') {
  mat-step-header:nth-of-type(#{$index}) {
    .mat-step-icon-not-touched span,
    .mat-step-icon span,
    .mat-step-icon-not-touched .mat-icon,
    .mat-step-icon .mat-icon {
      display: none;
    }

    @if ($label == '') {
      .mat-step-icon {
        height: 5px;
        width: 5px;
      }
    }

    .mat-step-icon-not-touched:after,
    .mat-step-icon:after {
      content: $label;
      position: absolute;
      left: 8px;
      top: 3px;
    }
  }
}

:host /deep/ {

  mat-step-header .mat-step-label {
      overflow: visible;
  }

  @include hide-option(1, '1');
  @include hide-option(2);
  @include hide-option(3);
  @include hide-option(4);
  @include hide-option(5, '2');
  @include hide-option(6);
  @include hide-option(7);
  @include hide-option(8);
  @include hide-option(9, '3');
  @include hide-option(10, '4');
  @include hide-option(11);
  @include hide-option(12, '5');
  @include hide-option(13, '6');
}

【讨论】:

  • 惊人的答案!非常感谢!
  • 非常感谢。但是,请按照我的问题更新中描述的问题:1)步进器的响应性; 2)正确的样式只有经过特定的stepper步骤后才能正确
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 2018-04-23
  • 1970-01-01
  • 2023-03-31
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多