Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align buttons in the MdDialog md-dialog-actions block

In the MdDialog's md-dialog-actions block, is it possible to align a button on the left while there are two buttons aligned to the right?

Here's a plnkr of some stuff I'm trying to do. Say, on the first modal, how do I separate the Yes and No buttons? (See the common-model.component.ts file) (This plnkr has some other issues to it that I'm still working on. But it doesn't involve this question.)

import { Component }   from '@angular/core';
import { MdDialogRef } from "@angular/material";

@Component({
    selector: 'common-modal',
    template: `
      <h2 md-dialog-title id="modal-title">{{ title }}</h2>
      <md-dialog-content>
        <p class="dialog-body" id="modal-message">{{ message }}</p>
      </md-dialog-content>
      <md-dialog-actions align="right">
        <button md-raised-button 
                md-dialog-close 
                id="modal-close-btn">
          {{ buttonOptions.closeText }}
        </button>
        <button md-raised-button 
                *ngIf="buttonOptions.enableNext" 
                id="modal-next-button"
                (click)="dialogRef.close(true)">
          {{ buttonOptions?.nextText }}
        </button>
      </md-dialog-actions>`,
})
export class CommonModalComponent {
    /**
     * {string} The text for the header or title of the dialog.
     */
    title: string;
    /**
     * {string} The text for the body or content of the dialog.
     */
    message: string;
    /**
     * closeText  {string}  The text of the close button. (No, Done, Cancel, etc)
     * nextText   {string}  The text of the confirming button. (Yes, Next, etc)
     * enableNext {boolean} True to show the next button. False to hide it.
     */
    buttonOptions: {
        closeText: string,
        nextText?: string,
        enableNext: boolean
    };


    constructor(public dialogRef: MdDialogRef<CommonModalComponent>) { }
}
like image 784
Machtyn Avatar asked Feb 02 '17 19:02

Machtyn


People also ask

How to fix mddialog when it is not working?

This can be fixed by updating the size of MDDialog at the end of initialisation. Sorry, something went wrong. @agisbrec I don’t understand what you are talking about. Sorry, something went wrong. When someone interacts with the dialog, it checks whether the touch was inside the dialog window, or outside. If it was outside, the dialog is dismissed.

What is MD-dialog in angular?

The md-dialog, an Angular Directive, is a container element and is used to display a dialog box.

How to fix collide_point property of mddialog is wrong?

or when children widgets change their size. Therefore, the collide_point property of MDDialog does not correspond to the real size of MDDialog. This can be fixed by updating the size of MDDialog at the end of initialisation. Sorry, something went wrong. @agisbrec I don’t understand what you are talking about.

How to right align a button in a box component?

Each Box component has basic styling applied via the sx prop. It is a common requirement to right align components in a UI layout. In the below code example, I use the Box component to right align a button. The Box component has props justifyContent and alignItems which can be used to quickly apply the CSS values justify-content and align-items.


1 Answers

You can align md-dialog-actions with the align attribute which is available Material 2.0.0-beta.2 on words. Update version if you are not on the latest. You can use "end" or "center" to align.

<md-dialog-actions align="end"> ... </md-dialog-action>

If you want to align buttons individually, it needs custom styles on them. Use custom styles on buttons to separate them as well (This may be fixed in next material version)

like image 98
PrazSam Avatar answered Oct 17 '22 20:10

PrazSam