I'm wondering if there is a way to resize mat-chip and mat-form-field to a smaller size? Currently, my mat-form-field for chips is really big and almost the same size as other fields, such as the description field, so I want the form fields for chips and the chip itself to be smaller.
<mat-chip-list #chipList>
<div>
<mat-chip *ngFor="let superTag of superTags" [selectable]="selectable" [removable]="removable"
(removed)="remove(superTag)">
<img class="super-icon" src="/assets/images/icons/super-tag-icon.svg">
{{superTag.tag}}
<mat-icon matChipRemove *ngIf="removable" matTooltip="Remove a super tag">cancel</mat-icon>
</mat-chip>
</div>
<div>
<input matInput #input [(ngModel)]="tagIn" [formControl]="tagCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" (matChipInputTokenEnd)="addTag()">
<!-- <img class="icon" src="/assets/images/icons/chevron-down-icon.svg" alt="down"> -->
</div>
</mat-chip-list>
.form {
// display: flex;
width: calc(100% - 80px);
height: 10px;
}
.icon {
margin-top: -12px;
}
.super-icon {
width: 15px;
margin-right: 8px;
}
.is-loading ::ng-deep .mat-option-text {
display: flex;
justify-content: center;
}
You can decrease the padding values. For me, this worked:
mat-chip {
padding: 4px 9px !important;
}
Adjust the values accordingly. Also, you can change the font-size if needed.
This is the approach I used:
:host ::ng-deep .mat-chip-list-wrapper mat-chip {
padding: 0 8px;
}
I am trying to get my material dialog to have an X button at the top right, but I am having problems with the positioning.
component.ts
this.d.open(loginComponent, {
width: '300px',
height: '',
panelClass: 'dialogC',
});
component.html
<mat-dialog-content>
<button mat-button class="close-icon" [mat-dialog-close]="true">
<mat-icon>close</mat-icon>
</button>
<h2 mat-dialog-title>Login</h2>
style.scss
.dialogC {
position: relative !important;
}
.close-icon {
position: absolute;
top: 0;
right: 0;
transform: translate(50%, -50%);
}
The X is just aligned to the left instead of top right. Suggestions?
Update, this is the problem I get after adding flex:
<button class="close" mat-button (click)="onNoClick()">X</button>
<h1 mat-dialog-title>Login</h1>
<div mat-dialog-content>
...
...
</div>
CSS: (Please give it in global (styles.css) or give ViewEncapsulation.NONE or else these styles wont affect.)
.cdk-overlay-pane.my-dialog {
position: relative!important;
}
.close.mat-button {
position: absolute;
top: 0;
right: 0;
padding: 5px;
line-height: 14px;
min-width: auto;
}
Note that in the CSS We now have a new class out of thin air .my-dialog
So, please mention that as panelClass in dialogRef like below,
this.dialog.open(DialogComponent, {
width: '250px',
panelClass: 'my-dialog',
..
..
This yields me the following result,
The easy way now is:
<div mat-dialog-title class="dialog-title">
<h2>Title</h2>
<button mat-icon-button aria-label="close dialog" mat-dialog-close>
<mat-icon>close</mat-icon>
</button>
</div>
And the dialog-title css is
.dialog-title {
display: flex;
justify-content: space-between;
align-items: center;
}
That's working on Angular 8.0.0
Using mat-icon-button it is necessary to add only the style below to the button.
.close-button{
float: right;
top:-24px;
right:-24px;
}
Functional example:
stackblitz
You can have the X at the title and display: flex ? Like this,
<div mat-dialog-title class="flex-container">
<h1>Login</h1>
<button mat-button class="close-icon" [mat-dialog-close]="true">
<mat-icon>close</mat-icon>
</button>
</div>
<div mat-dialog-content>
...
...
</div>
FlexBox to the rescue,
.flex-container { display: flex;}
SideNote: You can still use fxLayout instead of .flex-container
In your component HTML file add the following markup at the top of all elements.
<div mat-dialog-title style="float: right; font-weight: 700; cursor: pointer;" (click)="close()">X</div>
In your component TS file add the close function as follows.
close(): void {
this.dialogRef.close();
}
Don't forget to include the dialogRef inside the constructor as an argument
constructor(public dialogRef: MatDialogRef<YourDialogComponent>) {}
What I prefer is doing something like this -
.html file
<button class="close" mat-button mat-dialog-title (click)="closeDialog()">X</button>
By giving mat-dialog-title to the button I make sure it is in the top layer and then I give custom class to it, something like
.css file
.close.mat-button {
position: inherit;
top: 0;
right: 0;
padding: 2px;
line-height: 3px;
min-width: auto;
}
The button discussed above and my modal-content is in a parent div, which I display as flex and use as flex-direction: column
.dialog{
display: flex;
flex-direction: column;
}
.ts file
closeDialog() {
this.dialogRef.close();
}```
You can acheive this by applying some css styles to mat-icon, you can achieve this.
Mat-dialog looks as below.
<button mat-icon-button class="close-button" [mat-dialog-close]="true">
<mat-icon class="close-icon" color="warn">close</mat-icon>
</button>
<h1 mat-dialog-title>Hi {{data.name}}</h1>
<div mat-dialog-content>
<p>Hello World!</p>
</div>
Add the following css rules
// if you want to change the color of the icon
.material-icons.color_white {color: #ffffff;}
.close-button{
float: right;
top:-24px;
right:-24px;
}
//if you want some css animation
.close-icon {
transition: 1s ease-in-out;
}
.close-icon:hover {
transform: rotate(180deg);
}
//To place the x mark outside of the container
::ng-deep .icon-outside .close-button{
float: right;
top:-52px;
right:-52px;
}
::ng-deep .icon-outside .mat-dialog-container {
overflow: unset
}
Your mat-dialog consuming componnet should look as below
constructor(public dialog: MatDialog) {}
openDialog(): void {
const dialogRef = this.dialog.open(DialogComponent, {
width: '250px',
panelClass:'icon-outside',
data: {name: 'your name'}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
Adding custom class icon-outside is important.
This will change your code as expected.
If you are seeking to change the color of the icon, Add these two classes to mat-icon material-icons & color_white
So your button will look as below:
<button mat-icon-button class="close-button icon-outside" [mat-dialog-close]="true">
<mat-icon class="close-icon material-icons color_white">close</mat-icon>
</button>
I just ran into the same problem. I've come up with an easier solution using floats. This also aligns the close X with the title, which I find more visually pleasing.
HTML file:
<div>
<h1 mat-dialog-title style="float: left">Dialog Title</h1>
<span style="float: right" [mat-dialog-close]>X</span>
</div>
<div mat-dialog-content style="clear: both">
...
</div>
On our project I did an implementation using flex and css.
.html file
<div fxLayout="column">
<div fxLayoutAlign="end">
<button mat-icon-button color="primary" (click)="close()"><mat-icon>close</mat-icon></button>
</div>
<mat-card class="pd-2">
...
</mat-card>
</div>
.ts file
openMinimumsModal( ) {
const dialogRef = this.matDialog.open(OrderMinimumsComponent, {
width: 'auto',
panelClass: 'dialog-no-padding',
data: { ... },
});
dialogRef.afterClosed().subscribe(() => {});
}
close(): void {
this.dialogRef.close();
}
.css file
.dialog-no-padding .mat-dialog-container {
padding: 0;
}
.pd-2 {
padding: 0 20px 20px 20px !important;
}
Possible duplicate: 49420069
Close functionality and button alignment without TypeScript.
HTML:
<button class="button-close" mat-button [mat-dialog-close]="true">X</button>
CSS:
.button-close {
justify-self: right;
font-size: 20px;
border: none;
height: 30px;
background-color: #FFFFFF;
outline: none;
color: #c04747;
&:hover {
cursor: pointer;
}
}
I have problems with horizontal scrolling. My mat-tree implementation is from here. Vertical scrolling works perfectly but horizontal doesn't work. How to add it to my mat-tree? By using an overflow parameter I see the horizontal scrolling bar but it doesn't work, doesn't react to content and it is still disabled.
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding>
<button mat-icon-button disabled></button>
{{node.item}}
</mat-tree-node>
<mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
<button mat-icon-button
[attr.aria-label]="'toggle ' + node.filename" matTreeNodeToggle>
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
{{node.item}}
<mat-progress-bar *ngIf="node.isLoading"
mode="indeterminate"
class="example-tree-progress-bar"></mat-progress-bar>
</mat-tree-node>
</mat-tree>
.example-tree-progress-bar {
margin-left: 30px;
}
have you tried adding a class to the child mat-tree-node with the style overflow:visible!important .
Here is the complete class to be added btw.
.tree-node {
margin: 0;
padding: 0;
padding-right: 1%;
list-style: none;
border: none;
overflow: visible !important; /* notice here*/
}
works for me with https://github.com/angular/flex-layout/wiki/fxFlex-API, should be because of max-width=20% it sets on wrapping div:
<div fxFlex="1 1 20%" fxLayout="row" style="overflow: scroll">
<mat-tree fxFlex="0 0 auto" ...>
</div>
Try to add in your scss\css component the code below:
mat-tree {
overflow: auto;
}
mat-tree-node {
overflow: visible !important;
}
I want to change my icon to a button to use it as copy to clipboard method. But when I do it, the button moves to the right side. Only when I try a around the text it works but of course the formatting is broken.
<mat-list>
<h3 matSubheader>Persönliche Daten</h3>
<mat-list-item>
<button mat-icon-button ngxClipboard [cbContent]="firstname">
<mat-icon matListAvatar>account_box</mat-icon>
</button>
<h4 matLine>{{firstname}}</h4>
<p matLine>Vorname</p>
</mat-list-item>
<mat-divider [inset]="true"></mat-divider>
<mat-list-item>
<mat-icon matListAvatar>description</mat-icon>
<h4 matLine>{{lastname}}</h4>
<p matLine>Nachname</p>
</mat-list-item>
</mat-list>
My CSS:
mat-list-item mat-icon[matListAvatar], .mat-list-item-content mat-icon[matListAvatar] {
background-color: rgba(0,0,0,0.04);
}
mat-list-item mat-icon[matListAvatar], .mat-list-item-content mat-icon[matListAvatar] {
align-items: center;
align-content: center;
justify-content: center;
display: flex;
}
/deep/ .mat-list-item-content {
padding: 0!important;
}
/deep/ .mat-list-base .mat-subheader {
padding: 0!important;
}
p {
font-family: Lato;
color: rgba(0,0,0,.54);
}
Using the (click) property
You can just make the icon behave like a button.
Add a (click) property to it and call the function you want!
<mat-icon (click)="myFunction($event)" matListAvatar>account_box</mat-icon>
Then you can add some :hover css to it to make it feel like a button.
Using HTML/CSS
You can place any content next to the button in a wrapper, you can customize this one in the css to behave differently if needed (if you end up adding more data to display you might have to play around with the flex properties, margin... or you might need to have nested wrappers, etc...)
<button mat-icon-button >
<mat-icon matListAvatar>account_box</mat-icon>
</button>
<div class="test-wrapper">
<h4 matLine>{{firstname}}</h4>
<p matLine> Vorname</p>
</div>
with this css:
.test-wrapper{
padding-right: 0;
padding-left: 16px;
width: 100%;
display: flex;
flex-direction: column;
}
.test-wrapper > *{
margin: 0;
}
I have the following HTML:
<div class="total">
<span id="pledged-money" class="money">
<p>${{ total.amount }}
<span class="btn btn-xs btn-info question-mark"
data-toggle="tooltip"
data-placement="top"
title="Hello there">
!
</span>
</p>
</span>
</div>
with the following scss:
#pledged-money {
p {
display: block;
position: relative;
}
span {
position: absolute;
top: 22%;
margin-left: 10px ;
font-size: 0.5em;
width: 9%;
}
}
As a result I have the following:
So far everything is okay, but what I need is to display a dialog when clicking on this span element like this:
I have not too much experience with HTML and CSS and I am currently stuck with this. How can I display this element that has a close button and the dialog pointing to the span element.
If you use bootstrap, it would be very easy to implement the popup message.
Use bootstrap popover, here is the link for reference https://www.w3schools.com/bootstrap/bootstrap_popover.asp