-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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): custom class option #4718 #4012 #4722
Conversation
Extend dialog config options to allow custom dialog class. Custom class enables media queries. angular#4718 angular#4012
I tried to run unit tests but I am getting chrome disconnected error message so it seems something is wrong with karma config. I've tried to increase timeouts but it didn't help. Also e2e test were failing even before my changes so couldn't test that either. |
Would it be possible to support the same syntax as ngClass? e.g. #4629 |
@willshowell that would be great though situation here is more complex as pane element is created dynamically so I'd need to handle all different types of class object to add classes with classList.add. I'll try |
Ah yes I see. I'm curious why you chose to add the class to the If you instead chose to attach to // dialog-container.ts
@Component({
// ...
host: {
+ '[class]': 'dialogConfig?.dialogClass',
'[class.mat-dialog-container]': 'true',
'[attr.role]': 'dialogConfig?.role',
'[@slideDialog]': '_state',
'(@slideDialog.done)': '_onAnimationDone($event)',
},
})
export class MdDialogContainer extends BasePortalHost { |
@@ -15,6 +15,9 @@ export class OverlayState { | |||
/** Strategy to be used when handling scroll events while the overlay is open. */ | |||
scrollStrategy: ScrollStrategy = new NoopScrollStrategy(); | |||
|
|||
/** Custom class to add to the dialog */ | |||
dialogClass: string = ''; |
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.
Overlay is the basis for multiple components, not just dialog. I would call this panelClass
.
src/lib/dialog/dialog-config.ts
Outdated
@@ -27,6 +27,9 @@ export class MdDialogConfig { | |||
/** The ARIA role of the dialog element. */ | |||
role?: DialogRole = 'dialog'; | |||
|
|||
/** Custom class for the dialog, */ | |||
dialogClass?: string = ''; |
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.
Probably call this panelClass
as well (this is already DialogConfig
, so using the word dialog
again on a property is redundant)
src/lib/core/overlay/overlay-ref.ts
Outdated
@@ -53,6 +53,10 @@ export class OverlayRef implements PortalHost { | |||
this._attachBackdrop(); | |||
} | |||
|
|||
if (this._state.dialogClass) { |
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.
There needs to be a unit test for this behavior in the overlay tests
src/lib/core/overlay/overlay-ref.ts
Outdated
@@ -69,6 +73,9 @@ export class OverlayRef implements PortalHost { | |||
this._togglePointerEvents(false); | |||
this._state.scrollStrategy.disable(); | |||
this._detachments.next(); | |||
if (this._state.dialogClass) { |
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.
I don't think removing the class is necessary
@willshowell I chose cdk-overlay-pane because when you use width dialog option it's set to that element so I guess that's the right one. |
@jbojcic1 understood, and I agree that it keeps it consistent. My personal use cases were for removing the dialog padding and overriding the dialog's max-width (see #4653). But after playing with it some, I see that you get better position control by having the selector on the Thanks for putting this PR together and once it's merged, I'll just use |
Changed custom class config option name. Remove unnecessary class removal on detach. angular#4718 angular#4012
Added missing unit test to check if overlay pane has custom panel class. angular#4718 angular#4012
@jelbourn pls check now |
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.
Just a couple last comments
@@ -15,6 +15,9 @@ export class OverlayState { | |||
/** Strategy to be used when handling scroll events while the overlay is open. */ | |||
scrollStrategy: ScrollStrategy = new NoopScrollStrategy(); | |||
|
|||
/** Custom class to add to the dialog */ |
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.
Comment still says "dialog", should say "overlay pane"
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.
Forgot that one :)
src/lib/core/overlay/overlay.spec.ts
Outdated
beforeEach(() => { | ||
config = new OverlayState(); | ||
config.panelClass = 'custom-panel-class'; | ||
}); |
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.
You don't really need the beforeEach
here; you can create the stats and set the class in the test itself because it's only being used once
Change wrong comment. Remove unnecessary beforeEach from test. angular#4718 angular#4012
@jelbourn done |
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.
LGTM
FYI, somebody is very much waiting for this merge. |
Any update when this will make it into a release? |
@jonsamwell not sure. Maybe @jelbourn will know? |
Very much looking forward to this 😬 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Extend dialog config options to allow custom dialog class. Custom class enables media queries.