Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dialog): support minWidth, minHeight, maxWidth and maxHeight #7488

Merged
merged 8 commits into from
Oct 9, 2017

Conversation

emilio-martinez
Copy link
Contributor

@emilio-martinez emilio-martinez commented Oct 3, 2017

Fixes #6024, Fixes #3209

  • Adds Dialog support for minWidth, minHeight, maxWidth and maxHeight via config. Mostly delegates to Overlay.
  • Moves declared max-width on .mat-dialog-container stylesheet to be authored via MatDialogConfig, providing the same default 80vw value. Without this change, there would likely be undesired layout results due to different constraints being set on the overlay container vs the nested the dialog container.
  • Added note on minHeight and maxHeight regarding the potential need to also set a height due to the rules around computed height resolution (https://www.w3.org/TR/CSS2/visudet.html#min-max-widths). Any value set on height as a default would probably be assuming too much and may have varying results across browsers.

* Adds Dialog support for `minWidth`, `minHeight`, `maxWidth` and `maxHeight` via config. Mostly delegates to Overlay.
* Moves declared `max-width` on `. mat-dialog-container` stylesheet to be authored via `MatDialogConfig`, providing the same default `80vw` value. Without this change, there would likely be undesired layout results due to different constraints being set on the overlay container vs the nested the dialog container.
* Added note on `minHeight` and `maxHeight` regarding the potential need to also set a `height` due to the rules around computed height resolution (https://www.w3.org/TR/CSS2/visudet.html#min-max-widths).  Any value set on `height` as a default would probably be assuming too much and may have varying results across browsers.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 3, 2017
Not adding `minWidth`, `minHeight`, `maxWidth` and `maxHeight` to `config` to avoid overriding the default value of `maxWidth` particularly—the type checker will require it to be a string. Instead, setting `config` to type `MatDialogConfig` is prefered to appease the type checker since those four properties are optional.
@emilio-martinez emilio-martinez force-pushed the dialog-6024 branch 3 times, most recently from 9aa50df to 401e686 Compare October 3, 2017 10:26
Appeases the AOT type checker for the template by extending `MatDialogConfig` to disallow `position` from being undefined, given that it’s optional. Guards cannot be set on the template because the values are bound to NgModel.
@emilio-martinez
Copy link
Contributor Author

Screenshot tests seem to be failing for components that—as far as I can tell—are unrelated to what this PR addresses. Screenshot test flagged: mdcard, mdtoolbar, and stepper.

} from '@angular/material';

/**
* Appeases the AOT type checker for the template by extending `MatDialogConfig`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not add a separate type just for the sake of AoT. You can remove the type from the config. It'll still be type-checked when it's passed in to dialog.open.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, dialog.open would type-check, but not having type results in AOT errors because the template would only have the inferred type to go off from:
Error at /home/travis/build/angular/material2/dist/packages/demo-app/dialog/dialog-demo.ngfactory.ts:526:51: Property 'minWidth' does not exist on type '{ disableClose: boolean; panelClass: string; hasBackdrop: boolean; backdropClass: string; width: ...'.
See https://travis-ci.org/angular/material2/jobs/282614008.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get it to play nice if you initialize the minWidth to something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisbeto another alternative would be to just type with MatDialogConfig without extending, but given strictNullChecks, AOT will complain in the template about config.property possibly being undefined, so something like the below could be done. Let me know your thoughts.

<ng-template [ngIf]="config.position">
  <p>
    <mat-form-field>
      <input matInput [(ngModel)]="config.position.top" (change)="config.position.bottom = ''" placeholder="Top">
    </mat-form-field>
    <mat-form-field>
      <input matInput [(ngModel)]="config.position.bottom" (change)="config.position.top = ''" placeholder="Bottom">
    </mat-form-field>
  </p>

  <p>
    <mat-form-field>
      <input matInput [(ngModel)]="config.position.left" (change)="config.position.right = ''" placeholder="Left">
    </mat-form-field>
    <mat-form-field>
      <input matInput [(ngModel)]="config.position.right" (change)="config.position.left = ''" placeholder="Right">
    </mat-form-field>
  </p>
</ng-template>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's over-complicating it. Initializing the new properties to empty strings should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed re: initializing the config props. The only question I'd have is around setting the value for maxWidth since I'm initializing with 80vw on DialogConfig. Initializing it to something neutral like an empty string would override the value.

To your point about initializing, it could be as simple as initializing all min/max values with an empty string and initializing maxWidth with the 80vw, or extracting the default value out of a new DialogConfig and setting that in the maxWidth init.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing all of them to an empty string (only in the demo) and the maxWidth to the same as the default is fine by me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Addressed in 2b1c733

/**
* Min-height of the dialog.
* For this value to be effectively applied, `height` may also need to be defined.
* See https://www.w3.org/TR/CSS2/visudet.html#min-max-widths
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this needs to link to the CSS spec. Something along the lines of /** min-height of the dialog */ should suffice. Same goes for the maxHeight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* For this value to be effectively applied, `height` may also need to be defined.
* See https://www.w3.org/TR/CSS2/visudet.html#min-max-widths
*/
minHeight?: string = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't need to be initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. What are your thoughts on initializing maxWidth? I left that initialized for the time being.

@emilio-martinez
Copy link
Contributor Author

emilio-martinez commented Oct 3, 2017

@crisbeto tests passing after your feedback with the same caveats regarding the screenshot tests noted above. Let me know if you have any further comments.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Oct 3, 2017
maxWidth?: string = '80vw';

/** Max-height of the dialog */
maxHeight?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be string | number, where a number implies a pixel value to match the OverlayConfig values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/** Min-height of the dialog */
minHeight?: string;

/** Max-width of the dialog. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should include Defaults to 80vw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jelbourn jelbourn removed the action: merge The PR is ready for merge by the caretaker label Oct 4, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Oct 5, 2017
@andrewseguin andrewseguin merged commit 57f19cd into angular:master Oct 9, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
5 participants