components icon indicating copy to clipboard operation
components copied to clipboard

MatDialog mat-dialog-actions is not at the bottom of the dialog

Open ashishdoneriya opened this issue 7 years ago • 48 comments

Bug:

Angular Material is not placing md-dialog-actions at the bottom

What is the expected behavior?

Should be at the bottom

What is the current behavior?

Currently, it is placed just after md-dialog-content

What are the steps to reproduce?

Add md-dialog-actions Providing a Plunker (or similar) is the best way to get the team to see your issue. Plunker template: https://plnkr.co/edit/S2D0g6NOPpVRYoc6KA7L?p=preview

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

angular 4, material ^2.0.0-beta.5, os ubuntu 16.04, typescript ~2.0.3, browser : chrome

ashishdoneriya avatar May 16 '17 22:05 ashishdoneriya

@crisbeto looks like this happens when explicitly setting a height on the dialog

jelbourn avatar May 18 '17 23:05 jelbourn

Oh this is for ng2, same is happening for me using material 1.1.3

beazergood avatar May 20 '17 06:05 beazergood

I can confirm it indeed seems to occur the moment you set a specific height on the dialog. The moment you specify an height (in my case 65%) the title and actions don't stay fixed in place and there are 2 scrollbars. See:

https://plnkr.co/edit/1Vn3D3E2ozdO80rLlleS?p=preview

rthewhite avatar May 30 '17 12:05 rthewhite

Also duplicate of https://github.com/angular/material2/issues/4053

rthewhite avatar May 30 '17 13:05 rthewhite

Is there any news about this issue?

thanks

ChenReuven avatar Nov 12 '17 06:11 ChenReuven

Any news?

pauloapi avatar Apr 04 '18 07:04 pauloapi

The other ticket points to this ticket :D but I can't see any solution(?)

Chris2011 avatar Apr 10 '18 11:04 Chris2011

I have found this to work as a temporary fix when explicitly setting height on a MatDialog.

my-dialog.component.html:

<div class="fixActionRow">
    <h1 mat-dialog-title></h1>
    <div mat-dialog-content></div>

    <div class="spacer"></div>

    <div mat-dialog-actions></div>
</div>

my-dialog.component.css:

.fixActionRow {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.spacer {
  flex-grow: 1;
}

atrombet avatar Apr 18 '18 02:04 atrombet

Is this a feature instead of a bug? Are we intended to replicate this ourselves? This issue has been open a longgg time

stephengardner avatar Jun 16 '18 13:06 stephengardner

not specifying the height worked for me.

fergalddaly avatar Jul 03 '18 16:07 fergalddaly

Is there any update about this issue? @jelbourn

vinagreti avatar Sep 26 '18 21:09 vinagreti

Material 2 is hopeless. Switched to Vuejs for Vuetify

ashishdoneriya avatar Sep 27 '18 20:09 ashishdoneriya

Please reopen the bug ticket, it was not implemented and to say moving to vue will not resolve the ticket. @ashishdoneriya if you are not interested anymore in it, fine, but leave it open for everyone else. Thx.

Chris2011 avatar Sep 28 '18 07:09 Chris2011

@Chris2011 ok chris

ashishdoneriya avatar Sep 28 '18 12:09 ashishdoneriya

My experience:

Bug, feature request, or proposal: Bug

What is the expected behavior? Actions to be at the bottom of the dialog

What is the current behavior? Actions right after content

What are the steps to reproduce? StackBlitz starter: https://stackblitz.com/edit/angular-cuikyx

Which versions of Angular, Material, OS, TypeScript, browsers are affected? [email protected], [email protected], any browser and any OS

vinagreti avatar Sep 28 '18 13:09 vinagreti

@crisbeto I saw that you are working on dialog fixes. Could you please tell us if this issue will be fixed? It was opened more than a year ago and nothing has been done. Thanks a lot!!!

vinagreti avatar Oct 02 '18 18:10 vinagreti

There really really needs to be a better way to specify different dialog scaling strategies beyond the existing positioning strategies (such as full screen with an optional margin). Then problems like this would go away.

I expect the primary reason to set height on a dialog in the first pace is to make it stretch, or stop it overflowing the page. The number one thing a dialog control should do it take the burden of sizing away from me!

simeyla avatar Oct 20 '18 02:10 simeyla

Any news or workaround for this? @atrombet's solution didn't work for me. =(

0xDones avatar Nov 30 '18 22:11 0xDones

@dpolicastro https://stackblitz.com/edit/angular-cuikyx-pnx9we

manklu avatar Nov 30 '18 23:11 manklu

Thanks @manklu, I faced some issue trying to make it work on my project, and noticed that using minHeight property was not enought, you have to set the height. So the solution that @atrombet proposed works properly.

const dialogRef = this.dialog.open(MyDialog, {
      width: '80%',
-      minHeight: '500px',
+      height: '80%'
 });

0xDones avatar Dec 01 '18 01:12 0xDones

This issue(double scroll(container & content area)) has happened when I set height explicitly !!

const dialogConfig: MatDialogConfig = {
      panelClass: 'my-panel',
      maxWidth: '50vw',
       maxHeight: '70vh',

      width: '30vw',
      height: '30vh'
    }

curiouscod3 avatar Apr 13 '19 13:04 curiouscod3

I have found this to work as a temporary fix when explicitly setting height on a MatDialog.

my-dialog.component.html:

<div class="fixActionRow">
    <h1 mat-dialog-title></h1>
    <div mat-dialog-content></div>

    <div class="spacer"></div>

    <div mat-dialog-actions></div>
</div>

my-dialog.component.css:

.fixActionRow {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.spacer {
  flex-grow: 1;
}

This worked very well. However, there was still a gap from the mat actions' top part between content and actions when I made height 95%. I resolved this with adding: .mat-dialog-content { max-height: 100%; }

etonyali avatar Apr 16 '19 16:04 etonyali

I think problem is cause by mat-dialog-content max height set to 65vh...

Resolved with :

.mat-dialog-content {
    max-height: initial !important;
}

JrmyDev avatar Apr 23 '19 14:04 JrmyDev

@JrmyDev this worked well. you can see it in action here https://stackblitz.com/edit/angular-cuikyx-7vewfm

vinagreti avatar Apr 23 '19 17:04 vinagreti

I think problem is cause by mat-dialog-content max height set to 65vh...

Resolved with :

.mat-dialog-content {
    max-height: initial !important;
}

Issue I am having with that is when I set encapsulation: ViewEncapsulation.None, it messes up. However max-height: 100%; works without an issue.

etonyali avatar Apr 24 '19 13:04 etonyali

To sum up for everybody looking for a clean solution, that is maintainable and can be removed once this is fixed:

// app.module.ts
import {MAT_DIALOG_DEFAULT_OPTIONS} from '@angular/material';
...
providers: [
    {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {panelClass: 'mat-dialog-override'}}
]
...
// overrides.scss or styles.scss
// This fixes https://github.com/angular/components/issues/4609
.mat-dialog-override {
  mat-dialog-container {
    > :first-child {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    mat-dialog-content,
    div[mat-dialog-content] {
      flex-grow: 1;
      max-height: unset;
    }
  }
}

Stackblitz: https://stackblitz.com/edit/angular-gjeekg For Debugging this Bug: It only appears if the height of the Dialog is explicitly set via minHeight or height.

DanielHabenicht avatar Sep 06 '19 13:09 DanielHabenicht

two years talking about it and posting solutions in comments instead of fixing it... :(

leandro-hl avatar Sep 30 '19 13:09 leandro-hl

Yes, please fix this. Workarounds are fine, but it is a lot more time saving if it comes placed correctly out of the box. :(

lekha-badarinath avatar Oct 15 '19 09:10 lekha-badarinath

As @dpolicastro mentioned none of these solutions work if only minHeight and not height) is set.

rockResolve avatar May 22 '20 03:05 rockResolve

Hey guys! Time to fix it! Every workaround makes my code just ugly...

breket avatar Jun 15 '20 01:06 breket

I refined the above work of @DanielHabenicht to handle minHeight.

helper my-dialog.component.css:

// HACK Work around for Angular Material bug
// Setting height or min-height placed .mat-dialog-actions immediately below mat-dialog-content
// It should be at the bottom.
// Issue & fix https://github.com/angular/components/issues/4609
// Below css requires code to fix min-height.
// Search 'DIALOG MIN HEIGHT' for paired code fix
mat-dialog-container {
  display: block;
  height: 100%;

  .my-dialog {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: inherit;
  }

  .mat-dialog-title {
    display: block;
  }

  .mat-dialog-content {
    flex-grow: 1;
    max-height: unset;
  }
}

paired with helper dialog.service.ts:

  showDialog<T, D = any, R = any>(
    componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
    config?: MatDialogConfig<D>
  ) {
    return this.dialog.open(
      componentOrTemplateRef,
      createConfig(config)
    );
  }

  private createConfig(config: MatDialogConfig<any> | undefined) {
    return {
      // First Default settings
      width: '570px',

      // minHeight: '300px',
      // Remove mat-dialog-container padding 48px so it can be inherited by
      // mat-dialog-container first child. Inherit makes mat-dialog-container
      // first child too high by padding.
      // So calculate as 300px - 48px of mat-dialog-container padding
      // Search 'DIALOG MIN HEIGHT' for paired css fix
      minHeight: '252px',

      disableClose: true,

      // Then User settings
      ...config
    };
  }

To make the height & minHeight property values pass down to the dialog body's container, each parent (i.e. my-dialog) between it and ancestor mat-dialog must pass them through e.g. ...

dialog instance component my-confirm-dialog.component.scss

my-confirm-dialog {
  height: 100%;
  min-height: inherit;
}

and set viewEncapsulation none with my-confirm-dialog.component.ts

@Component({
  selector: 'my-confirm-dialog',
  templateUrl: './my-confirm-dialog.component.html',
  styleUrls: ['./my-confirm-dialog.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class MyConfirmDialogComponent implements OnInit {

rockResolve avatar Jul 01 '20 23:07 rockResolve

Any news? Definitely moving to react or vue, tired of this WorkAroungular life

Mgiannig avatar Jul 03 '20 16:07 Mgiannig

@austinkulp It isn't a framework. It is only a lib and has nothing to compare with Vue. But, it is really a shame they still didn't fix it.

vinagreti avatar Sep 09 '20 14:09 vinagreti

@DanielHabenicht this is great, but it seems to remove my backdrop... 🤔 Upon removing the override the backdrop returns. Any idea how these are correlated?

EDIT: Seems as though overriding the panelClass also overrides all the other default values, including hasBackdrop. This fixes it:

{ provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: { panelClass: 'mat-dialog-override', hasBackdrop: true }}

alekplay avatar Sep 18 '20 22:09 alekplay

For me,

.mat-dialog-content {
  height: 100%;
}

did the trick, when I have a set dialog height

const dialogConfig = new MatDialogConfig();
dialogConfig.height = '80%';

jurgh1 avatar Mar 29 '21 13:03 jurgh1

Hello, is there any work on it from Angular developers? It is shown here that it is a known bug and a requested important feature. Please help. Maybe with a good workaround... !? Thanks!

skwiotek avatar Apr 26 '21 07:04 skwiotek

The proposed fix didn't worked for me. Following code solved my case (when specifying height: '85vh' in this.dialog.open):

.mat-dialog-content {
  max-height: initial!important;
  height: calc(100% - 52px);
}

.mat-dialog-container {
  max-height: 90vh;
}

zdenek-horak avatar Jul 21 '21 10:07 zdenek-horak

The bug is still present in Angular Material 13 😕

SadiinsoSnowfall avatar Dec 10 '21 13:12 SadiinsoSnowfall

Leaving a comment to note that this is still a popular issue that devs want fixed please. Work-arounds are ugly.

ChelseaChilders avatar Jan 12 '22 21:01 ChelseaChilders

Also jumping on here to be annoying and say this bug is still present

SelectiveHouse avatar Jan 31 '22 13:01 SelectiveHouse

Using Angular 13. If I don't set the height of the dialog component then the dialog's action buttons are nicely positioned at the bottom of the dialog. However, when internal dialog's content changes size (say, tabs and each tab is different height) then the whole dialog window is resizing depending on the content. This is quite frustrating UX, so I'd have fixed the height of the dialog. With this, I get another issue, this time UI related, the action buttons sometimes end up in the middle of the dialog. The whole situation cannot be helped with the fact that styling dialogs without turning off viewEncapsulation isn't possible.

lacamilla avatar Feb 07 '22 13:02 lacamilla

Also jumping on here to be annoying and say this bug is still present

Joining the queue. The proposed solutions in the comments are not satisfying at all.

JanBA1990 avatar Feb 23 '22 14:02 JanBA1990

Some fix for this ?

image

My project dependencies:

"@angular/material": "^14.0.3"

AlonsoK28 avatar Jul 18 '22 21:07 AlonsoK28