Skip to content

Commit 5c47e10

Browse files
committed
fixup! fix(material/dialog): css structure change
1 parent 07101a6 commit 5c47e10

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

src/material/dialog/_mdc-dialog-structure-overrides.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
// this for the dialog content scrolling (as explained above), and since we allow for
3232
// custom positioning through overlay configuration, we remove the rectangle
3333
// restrictions and scale based on the CDK overlay container.
34-
&, .mdc-dialog__container, .mdc-dialog__surface {
34+
&,
35+
.mdc-dialog__container,
36+
.mdc-dialog__surface {
3537
max-height: inherit;
3638
min-height: inherit;
3739
min-width: inherit;
@@ -47,12 +49,12 @@
4749
// When a component is passed into the dialog, the host element interrupts
4850
// the `display:flex` from affecting the dialog title, content, and
4951
// actions. To fix this, we make the component host `display: flex` by
50-
// marking it's panel with the `mat-mdc-dialog-component-panel` class.
52+
// marking its host with the `mat-mdc-dialog-component-host` class.
5153
//
5254
// Note that this problem does not exist when a template ref is used since
5355
// the title, contents, and actions are then nested directly under the
5456
// dialog surface.
55-
.mat-mdc-dialog-component-panel .mat-mdc-dialog-surface > * {
57+
.mat-mdc-dialog-component-host {
5658
display: flex;
5759
flex-direction: column;
5860
width: 100%;

src/material/dialog/dialog-container.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {DOCUMENT} from '@angular/common';
1212
import {
1313
ChangeDetectionStrategy,
1414
Component,
15+
ComponentRef,
1516
ElementRef,
1617
EventEmitter,
1718
Inject,
@@ -24,6 +25,7 @@ import {MatDialogConfig} from './dialog-config';
2425
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2526
import {CdkDialogContainer} from '@angular/cdk/dialog';
2627
import {coerceNumberProperty} from '@angular/cdk/coercion';
28+
import {ComponentPortal} from '@angular/cdk/portal';
2729

2830
/** Event that captures the state of dialog container animations. */
2931
interface LegacyDialogAnimationEvent {
@@ -323,4 +325,18 @@ export class MatDialogContainer extends _MatDialogContainerBase implements OnDes
323325
}
324326
});
325327
}
328+
329+
override attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
330+
// When a component is passed into the dialog, the host element interrupts
331+
// the `display:flex` from affecting the dialog title, content, and
332+
// actions. To fix this, we make the component host `display: flex` by
333+
// marking its host with the `mat-mdc-dialog-component-host` class.
334+
//
335+
// Note that this problem does not exist when a template ref is used since
336+
// the title, contents, and actions are then nested directly under the
337+
// dialog surface.
338+
const ref = super.attachComponentPortal(portal);
339+
ref.location.nativeElement.classList.add('mat-mdc-dialog-component-host');
340+
return ref;
341+
}
326342
}

src/material/dialog/dialog.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,6 @@ export abstract class _MatDialogBase<C extends _MatDialogContainerBase> implemen
162162
config.id = config.id || `${this._idPrefix}${uniqueId++}`;
163163
config.scrollStrategy = config.scrollStrategy || this._scrollStrategy();
164164

165-
// When a component is passed into the dialog, the host element interrupts
166-
// the `display:flex` from affecting the dialog title, content, and
167-
// actions. To fix this, we make the component host `display: flex` by
168-
// marking it's panel with the `mat-mdc-dialog-component-panel` class.
169-
//
170-
// Note that this problem does not exist when a template ref is used since
171-
// the title, contents, and actions are then nested directly under the
172-
// dialog surface.
173-
if (!(componentOrTemplateRef instanceof TemplateRef)) {
174-
this._appendPanelClass(config, 'mat-mdc-dialog-component-panel');
175-
}
176-
177165
const cdkRef = this._dialog.open<R, D, T>(componentOrTemplateRef, {
178166
...config,
179167
positionStrategy: this._overlay.position().global().centerHorizontally().centerVertically(),
@@ -261,17 +249,6 @@ export abstract class _MatDialogBase<C extends _MatDialogContainerBase> implemen
261249
dialogs[i].close();
262250
}
263251
}
264-
265-
/** Appends the given class name to the panel via the dialog config. */
266-
private _appendPanelClass(config: MatDialogConfig, className: string) {
267-
if (Array.isArray(config.panelClass)) {
268-
config.panelClass.push(className);
269-
} else if (typeof config.panelClass === 'string') {
270-
config.panelClass = [config.panelClass, className];
271-
} else {
272-
config.panelClass = className;
273-
}
274-
}
275252
}
276253

277254
/**

tools/public_api_guard/material/dialog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { AnimationTriggerMetadata } from '@angular/animations';
88
import { CdkDialogContainer } from '@angular/cdk/dialog';
99
import { ComponentFactoryResolver } from '@angular/core';
10+
import { ComponentPortal } from '@angular/cdk/portal';
1011
import { ComponentRef } from '@angular/core';
1112
import { ComponentType } from '@angular/cdk/overlay';
1213
import { DialogRef } from '@angular/cdk/dialog';
@@ -199,6 +200,8 @@ export class MatDialogContainer extends _MatDialogContainerBase implements OnDes
199200
constructor(elementRef: ElementRef, focusTrapFactory: FocusTrapFactory, document: any, dialogConfig: MatDialogConfig, checker: InteractivityChecker, ngZone: NgZone, overlayRef: OverlayRef, _animationMode?: string | undefined, focusMonitor?: FocusMonitor);
200201
_animationsEnabled: boolean;
201202
// (undocumented)
203+
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;
204+
// (undocumented)
202205
protected _contentAttached(): void;
203206
// (undocumented)
204207
ngOnDestroy(): void;

0 commit comments

Comments
 (0)