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): add dialog content elements #2090

Merged
merged 9 commits into from
Dec 16, 2016

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 6, 2016

Adds the following dialog-specific directives:

  • md-dialog-close - Closes the current dialog.
  • md-dialog-title - Title of a dialog.
  • md-dialog-content - Scrollable content for a dialog.
  • md-dialog-actions - Container for the bottom buttons in a dialog.

Fixes #1624.
Fixes #2042.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 6, 2016
@pietie
Copy link

pietie commented Dec 7, 2016

Out of interest, why is the md-dialog-title selector just an attribute?
If I compare it with md-card I would have expected it to be <md-dialog-title>

@crisbeto
Copy link
Member Author

crisbeto commented Dec 7, 2016

It's there to encourage you to use the appropriate native elements @pietie (e.g. h1, h2 etc), although I should've probably scoped it to those nodes. I'll add it later today. As for the card, I'm not sure what the reasoning is, but I suppose it's because the heading elements aren't always appropriate.

@clydin
Copy link
Member

clydin commented Dec 7, 2016

Have you considered an "align" attribute on md-dialog-actions similar to md-card? "center" would also be a nice addition to start|end as well.

@crisbeto
Copy link
Member Author

crisbeto commented Dec 7, 2016

Nope, I followed the example from #1624, but it sounds reasonable.

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.

I pulled it down and this looks like just what I had in mind. Thanks!

I like the idea of adding align to md-dialog-actions in a follow-up PR.

@Directive({
selector: '[md-dialog-title]',
host: {
role: 'heading'
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 we should put a role on this- the user should just put it on the appropriate element (h2, header, etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it in case the attribute was added to something like a div. I'll scope the selector to the proper nodes.

@Directive({
selector: '[md-dialog-content], md-dialog-content',
host: {
role: 'main'
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 we should have this role; nothing in the W3C authoring practices mentiones it and the docs for role="main" says there should only be one per "document" (for which a modal dialog doesn't count).

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't the content have some kind of role? The main was the only one I could find that seemed to fit.

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 it needs a role at all

}

[md-dialog-title] {
font-size: rem(2);
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to avoid using this rem function for now... the fact that it's even here is a leftover from an earlier version. During beta we're going to work on a more comprehensive typography solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

What should I go with in this case? Put in the computed value?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, go ahead with the computed value for now.

display: block;

&:last-child {
margin-bottom: -$md-dialog-padding;
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment explaining what this style is for?

* Button that will close the current dialog.
*/
@Directive({
selector: 'button[md-dialog-close]',
Copy link
Member

Choose a reason for hiding this comment

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

Also add mat- prefixed selectors (will be used for material1 compatibility mode).

$md-dialog-padding: 24px !default;
$md-dialog-border-radius: 2px !default;
$md-dialog-max-width: 80vw !default;
$md-dialog-max-height: 65vh !default;
Copy link
Member

Choose a reason for hiding this comment

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

Where do these max-height and max-width come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

The max-width is the same that Material 1 used, the max-height is arbitrary. M1 has 80% for the max-height as well, although that's for the entire dialog, whereas here we only have it on the md-dialog-content.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to set a max-width and max-height at all, then? I could imagine some people wanting to do a full-screen dialog.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd say so, otherwise the dialog content won't become scrollable. Also I'm not sure whether fullscreen dialogs are in the spec.

Copy link

@chpasha chpasha Dec 23, 2016

Choose a reason for hiding this comment

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

actually yes, there are fullscreen dialogs in material guidelines https://material.io/guidelines/components/dialogs.html#dialogs-full-screen-dialogs

[md-dialog-title] {
font-size: rem(2);
font-weight: bold;
letter-spacing: 0.005em;
Copy link
Member

Choose a reason for hiding this comment

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

Why is letter-spacing necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with whatever M1 was doing, I'm not sure what the reasoning for it was.

Copy link
Member

Choose a reason for hiding this comment

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

Let's remove it, then.

selector: 'button[md-dialog-close]',
host: {
'(click)': 'dialog.closeTop()'
}
Copy link
Member

Choose a reason for hiding this comment

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

We need to add a default aria-label to this that says "Close dialog". Also a unit test that ensures an aria-label set by the user overrides the default.

@@ -0,0 +1,49 @@
import {Directive} from '@angular/core';
Copy link
Member

Choose a reason for hiding this comment

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

Let's call this file dialog-content-directives.ts

@Directive({
selector: 'button[md-dialog-close]',
host: {
'(click)': 'dialog.closeTop()'
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 this will work for situations where there are two dialogs open side-by-side instead of one on top of the other. I took a poke at the code and found that you can inject the MdDialogRef here because the content is loaded with an instance of DialogInjector, so this works:

/**
 * Button that will close the current dialog.
 */
@Directive({
  selector: 'button[md-dialog-close]',
  host: {
    '(click)': 'dialogRef.close()'
  }
})
export class MdDialogClose {
  constructor(public dialogRef: MdDialogRef<any>) { }
}

With this change, I don't think we need closeTop any more.

Copy link
Member

Choose a reason for hiding this comment

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

Was going to say pretty much the same thing. As is it will break some more exotic use cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went this route since it's not currently possible to have multiple dialogs side-by-side. Also I wasn't aware of the DialogInjector. I'll try it out.

@crisbeto
Copy link
Member Author

crisbeto commented Dec 8, 2016

Addressed the feedback @jelbourn.

@jelbourn
Copy link
Member

LGTM, just needs rebase. Go ahead and apply the merge_ready label when it's rebased

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Dec 14, 2016
@jelbourn jelbourn merged commit cac72aa into angular:master Dec 16, 2016
@chpasha
Copy link

chpasha commented Dec 23, 2016

is it possible to override md-dialog-max-width somehow? I'm unable to change it to anything else in spite of !default attribute. The space is precious especially in xs-sm, hard coded 80vw seems to be too small

@chpasha
Copy link

chpasha commented Dec 23, 2016

one more thing - material design guidelines for dialogs (except for alertdialog) have an toolbar at the top, did you consider the possibility to give an option of aligning md-dialog-actions to the top or introducing one more directive like md-dialog-toolbar? It would be also awesome if that toolbar could have home button, title and action areas

@crisbeto
Copy link
Member Author

@chpasha

  1. How are you trying to override the max width? If overriding the SASS variable doesn't work, you should still be able to set this somewhere in your stylesheet:
md-dialog-container {
  max-width: <some value>;
}
  1. The point of this PR was to get some of the dialog content elements as a base. We'll probably keep improving on them in the future.

@chpasha
Copy link

chpasha commented Dec 23, 2016

  1. yes, selector in css works but I was hoping for more elegant solution via scss. Is there any point for defining those properties as !default since they cannot be overwritten in client library?
  2. 👍 fullscreen-style dialogs with toolbar at the top and basic elements like home button, title, content and action buttons would be cool

@antonyRoberts
Copy link

antonyRoberts commented Jan 5, 2017

@crisbeto Where exactly might you override the max-width in the CSS? Setting it on the parent component calling the Dialog or the Dialog itself's style does not seem to change the max-width to whatever it is set to.
Fullscreen dialogues are important for mobile.

http://plnkr.co/edit/7CE3VG1LUj2VtLCtdaOM?p=preview

@chpasha Did you have any luck?

@chpasha
Copy link

chpasha commented Jan 6, 2017

yes, I did succeed http://plnkr.co/edit/B46euKJxtf8RXu1O0smZ?p=preview
two changes

  1. encapsulation: ViewEncapsulation.None on Component
  2. md-dialog-container (not .md-dialog-container) in styles - and don't forget that it wont grow bigger if you content is small - to see that it works, I added width: 100vw

@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 6, 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
Development

Successfully merging this pull request may close these issues.

MdDialog Content Overflow Add dialog content elements
7 participants