-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(overlay): add ability to set custom class on panes #1438
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
.demo-dialog { | ||
color: rebeccapurple; | ||
} | ||
|
||
// apply custom z-index | ||
/deep/ .md-overlay-pane { | ||
&.jazz-dialog { | ||
z-index: 9999; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import {MdDialog, MdDialogConfig, MdDialogRef} from '@angular/material'; | |
moduleId: module.id, | ||
selector: 'dialog-demo', | ||
templateUrl: 'dialog-demo.html', | ||
styleUrls: ['dialog-demo.css'], | ||
styleUrls: ['dialog-demo.css'] | ||
}) | ||
export class DialogDemo { | ||
dialogRef: MdDialogRef<JazzDialog>; | ||
|
@@ -18,6 +18,7 @@ export class DialogDemo { | |
open() { | ||
let config = new MdDialogConfig(); | ||
config.viewContainerRef = this.viewContainerRef; | ||
config.paneClassName = 'jazz-dialog'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be part of the demo |
||
|
||
this.dialogRef = this.dialog.open(JazzDialog, config); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this |
||
|
||
// TODO(jelbourn): configuration still to add | ||
// - overlay size | ||
// - focus trap | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
z-index: $md-z-index-overlay-container; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// A single overlay pane. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ export class Overlay { | |
* @returns A reference to the created overlay. | ||
*/ | ||
create(state: OverlayState = defaultState): OverlayRef { | ||
return this._createOverlayRef(this._createPaneElement(), state); | ||
return this._createOverlayRef(this._createPaneElement(state), state); | ||
} | ||
|
||
/** | ||
|
@@ -52,10 +52,21 @@ export class Overlay { | |
* Creates the DOM element for an overlay and appends it to the overlay container. | ||
* @returns Promise resolving to the created element. | ||
*/ | ||
private _createPaneElement(): HTMLElement { | ||
private _createPaneElement(state: OverlayState): HTMLElement { | ||
var pane = document.createElement('div'); | ||
pane.id = `md-overlay-${nextUniqueId++}`; | ||
const id = nextUniqueId++; | ||
pane.id = `md-overlay-${id}`; | ||
pane.classList.add('md-overlay-pane'); | ||
pane.classList.add(`md-has-index-${id}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this class for? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I won't mind removing it though, you tell me. |
||
|
||
if (state.paneClassName) { | ||
// check if custom class is an array of classes | ||
if (state.paneClassName.constructor === Array) { | ||
pane.classList.add(...<Array<string>>state.paneClassName); | ||
} else { | ||
pane.classList.add(<string>state.paneClassName); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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);
} |
||
|
||
this._overlayContainer.getContainerElement().appendChild(pane); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// TODO(jelbourn): add configuration for size, clickOutsideToClose, lifecycle hooks, | ||
// ARIA labelling. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,10 @@ export class MdDialog { | |
.centerHorizontally() | ||
.centerVertically(); | ||
|
||
if (dialogConfig.paneClassName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
state.paneClassName = dialogConfig.paneClassName; | ||
} | ||
|
||
return state; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.