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(overlay): add ability to set custom class on panes #1438

Closed
wants to merge 3 commits into from

Conversation

fxck
Copy link
Contributor

@fxck fxck commented Oct 5, 2016

It's more of a proof-of-concept for #1432, since I feel like you'd rather control this by passing the config a z-index value, but I think this is more flexible(for example when you need to control this with css media queries).

What I've changed:

Overlay - You can pass paneClassName, which can be either a string or an array of string, to a config for Overlays create, it then adds it to the created md-overlay-pane, I have also added a new helper class to it md-has-index-${id}(which can then be used along your custom class to differentiate between more panes inside one overlay)

Dialog - added paneClassName option to MdDialogConfig, which is then passes to OverlayState and create example in the dialog-demo

Menu - added a new @Input to md-menu, which takes either a string or array of string, and passes it down to OverlayState in [md-menu-trigger-for]

Overlay - removed z-index from overlay.scss as it was making z-indexes of panes useless

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement labels Oct 5, 2016
@fxck fxck changed the title feat(overlay) add ability to set custom class on panes feat(overlay): add ability to set custom class on panes Oct 5, 2016
@fxck
Copy link
Contributor Author

fxck commented Oct 23, 2016

@jelbourn can I have some feedback please? I'm having a really hard time with overlays and components using them without this feature..

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.

Needs unit tests for all the added behaviors.

(In general, I'll hold off on reviewing PRs without tests since they seem to not be done yet)

@@ -18,6 +18,7 @@ export class DialogDemo {
open() {
let config = new MdDialogConfig();
config.viewContainerRef = this.viewContainerRef;
config.paneClassName = 'jazz-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 doesn't need to be part of the demo

@@ -1,3 +1,10 @@
.demo-dialog {
color: rebeccapurple;
}

// apply custom z-index
/deep/ .md-overlay-pane {
Copy link
Member

Choose a reason for hiding this comment

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

We're avoiding using /deep/ at all in material2.

@@ -12,6 +12,9 @@ export class OverlayState {
/** Whether the overlay has a backdrop. */
hasBackdrop: boolean = false;

/** Optional custom class to be added to the pane. */
paneClassName: string | Array<string>;
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 make this overlayClass to align with backdropClass (I don't believe we expose the term "pane" in the public API).

@@ -20,7 +20,6 @@
left: 0;
height: 100%;
width: 100%;
z-index: $md-z-index-overlay-container;
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 should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it HAS to be removed, otherwise any inner z-index will be ignored.

See http://jsbin.com/mesujat/1/edit?html,css,output yellow is over green, despite it having thousand times higher z-index.

pane.classList.add('md-overlay-pane');
pane.classList.add(`md-has-index-${id}`);
Copy link
Member

Choose a reason for hiding this comment

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

What is this class for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you can more granularly control stacking order of multiple panes inside a single overlay.. I guess you could do the same with :nth-child.. but you know, with BEM and everything having a class could be handy.

I won't mind removing it though, you tell me.

} else {
pane.classList.add(<string>state.paneClassName);
}
}
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 this is a bit cleaner:

let overlayClass = state.overlayClass;
if (overlayClass) {
  if (typeof overlayClass == 'string') {
    overlayClass = [overlayClass];
  }
  pane.classList.add(...overlayClass);
}

@@ -14,6 +14,9 @@ export class MdDialogConfig {
/** The ARIA role of the dialog element. */
role: DialogRole = 'dialog';

/** Optional custom class to be added to dialog's overlay pane. */
paneClassName: string | Array<string>;
Copy link
Member

Choose a reason for hiding this comment

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

string | string[]

@@ -120,6 +120,10 @@ export class MdDialog {
.centerHorizontally()
.centerVertically();

if (dialogConfig.paneClassName) {
Copy link
Member

Choose a reason for hiding this comment

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

What are your use-cases for exposing this through to dialog and menu? I can see the case for custom components built on top of overlay, but I'm not sure if it's the right API surface for the leaf components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The whole #1432 is a use-case for menu, see http://plnkr.co/edit/AqjYdsScCYPlK9w44aHQ?p=preview (try opening the menu and then clicking on something).. if I removed z-index from md-overlay-container, it would work, but only as long as my fixed element had z-index lower than 1000.. with this option I could simple set the menu pane to always have higher z-index.

Copy link
Contributor Author

@fxck fxck Oct 24, 2016

Choose a reason for hiding this comment

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

Same thing for dialog really, I could have a fixed element that will have z-index higher than 1000 and it would be overlaying the backdrop.

@fxck
Copy link
Contributor Author

fxck commented Oct 24, 2016

Closing in favour of #1584 ..

@fxck fxck closed this Oct 24, 2016
@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
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.

3 participants