使用正确的Angular Material directive,如何将方向更改为垂直?
从垂直标签开始:
然后想要下载mat-select下拉列表中的内容:
编辑:如果有人不打扰我,我会努力让https://stackoverflow.com/a/43389018适应我的答案:)
答案 0 :(得分:3)
写了angular-vertical-tabs。这只是简单地包裹@angular/material
mat-selection-list
,并使用@angular/flex-layout
重定向不同的屏幕尺寸。
<vertical-tabs>
<vertical-tab tabTitle="Tab 0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris tincidunt mattis neque lacinia dignissim.
Morbi ex orci, bibendum et varius vel, porttitor et magna.
</vertical-tab>
<vertical-tab tabTitle="Tab b">
Curabitur efficitur eleifend nulla, eget porta diam sodales in.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas vestibulum libero lacus, et porta ex tincidunt quis.
</vertical-tab>
<vertical-tab tabTitle="Tab 2">
Sed dictum, diam et vehicula sollicitudin, eros orci viverra diam, et pretium
risus nisl eget ex. Integer lacinia commodo ipsum, sit amet consectetur magna
hendrerit eu.
</vertical-tab>
</vertical-tabs>
答案 1 :(得分:2)
因此,我认为这不是完美的方法,但是它的代码很少,可以解决问题,并且似乎可以与mat-tab的其他功能很好地工作。
.mat-tab-group {
flex-direction: row !important;
}
.mat-tab-labels {
flex-direction: column !important;
}
.mat-tab-label-active {
border-right: 2px solid $primary-color !important;
}
.mat-ink-bar {
display: none;
}
由于相关类在组件范围之外呈现,因此您必须将封装设置为ViewEncapsulation。请注意:这可能与组件样式混为一谈。
这显然不能解决动画不足的问题,但对我来说,突出显示活动条就足够了,我只需隐藏原始墨水栏并添加一个模仿它的边框就可以实现
答案 2 :(得分:2)
将以下代码用于使用角形材料的垂直标签。
HTML
<div class="container">
<div id="content">
<div id="main-content">
<mat-tab-group>
<mat-tab label="Tab One">
Tab One Content
</mat-tab>
<mat-tab label="Tab Two">
Tab Two Content
</mat-tab>
</mat-tab-group>
</div>
</div>
</div>
SCSS
:host {
>.container {
max-width: 1264px;
width: 100%;
margin: 0 auto;
display: flex;
justify-content: space-between;
background: none;
}
/deep/ {
.mat-tab-group {
flex-direction: row;
}
.mat-tab-header {
border-bottom: none;
}
.mat-tab-header-pagination {
display: none !important;
}
.mat-tab-labels {
flex-direction: column;
}
.mat-ink-bar {
height: 100%;
left: 98% !important;
}
.mat-tab-body-wrapper {
flex: 1 1 auto;
}
}
}
.container {
position: relative;
width: 100%;
flex: 1 0 auto;
margin: 0 auto;
text-align: left;
}
#content {
box-sizing: content-box;
margin: 0 auto;
padding: 15px;
width: 1264px;
background-color: #ffffff;
}
#content {
max-width: 1100px;
width: 100%;
background-color: #ffffff;
padding: 24px;
box-sizing: border-box;
}
#content,
#main-content {
&::before,
&::after {
content: "";
display: table;
}
&::after {
clear: both;
}
}
答案 3 :(得分:1)
我对Angular非常陌生,并尝试使用选项卡,Sidenav和mat-action-list创建垂直选项卡。我不得不为带有隐藏标题的标签创建单独的组件(由于ViewEncapsulation.None用法)
我还不知道如何创建stackblitz内容。这是非常基本的实现。希望对别人有帮助。
app.component.html
<mat-sidenav-container class="side-nav-container">
<mat-sidenav mode="side" opened class="sidenav">
<mat-action-list>
<button mat-list-item (click)="index = 0"> tab 1 </button>
<button mat-list-item (click)="index = 1"> tab 2 </button>
</mat-action-list>
</mat-sidenav>
<mat-sidenav-content>
<app-tab-content [(index)]=index></app-tab-content>
</mat-sidenav-content>
</mat-sidenav-container>
app.component.css
.side-nav-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #eee;
}
.sidenav {
width: 200px;
background: rgb(15,62,9);
}
mat-action-list .mat-list-item {
color : white;
}
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
index: number;
}
tab-content.component.html
<mat-tab-group [(selectedIndex)]="index" class="header-less-tabs" animationDuration="0ms">
<mat-tab> Content 1 </mat-tab>
<mat-tab> Content 2 </mat-tab>
</mat-tab-group>
tab-content.component.css
.header-less-tabs.mat-tab-group .mat-tab-header {
display: none;
}
tab-content.component.ts
import { Component, OnInit, ViewEncapsulation, Input } from '@angular/core';
@Component({
selector: 'app-tab-content',
templateUrl: './tab-content.component.html',
styleUrls: ['./tab-content.component.css'],
encapsulation: ViewEncapsulation.None
})
export class TabContentComponent {
@Input() index: number = 1;
}