Skip to content

Commit 45dcfd5

Browse files
committed
fixup! fix(material/dialog): css structure change
1 parent cd6cb56 commit 45dcfd5

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 {
@@ -259,6 +261,20 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
259261
clearTimeout(this._animationTimer);
260262
}
261263
}
264+
265+
override attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
266+
// When a component is passed into the dialog, the host element interrupts
267+
// the `display:flex` from affecting the dialog title, content, and
268+
// actions. To fix this, we make the component host `display: flex` by
269+
// marking its host with the `mat-mdc-dialog-component-host` class.
270+
//
271+
// Note that this problem does not exist when a template ref is used since
272+
// the title, contents, and actions are then nested directly under the
273+
// dialog surface.
274+
const ref = super.attachComponentPortal(portal);
275+
ref.location.nativeElement.classList.add('mat-mdc-dialog-component-host');
276+
return ref;
277+
}
262278
}
263279

264280
const TRANSITION_DURATION_PROPERTY = '--mat-dialog-transition-duration';

src/material/dialog/dialog.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,6 @@ export class MatDialog implements OnDestroy {
165165
config.id = config.id || `mat-mdc-dialog-${uniqueId++}`;
166166
config.scrollStrategy = config.scrollStrategy || this._scrollStrategy();
167167

168-
// When a component is passed into the dialog, the host element interrupts
169-
// the `display:flex` from affecting the dialog title, content, and
170-
// actions. To fix this, we make the component host `display: flex` by
171-
// marking it's panel with the `mat-mdc-dialog-component-panel` class.
172-
//
173-
// Note that this problem does not exist when a template ref is used since
174-
// the title, contents, and actions are then nested directly under the
175-
// dialog surface.
176-
if (!(componentOrTemplateRef instanceof TemplateRef)) {
177-
this._appendPanelClass(config, 'mat-mdc-dialog-component-panel');
178-
}
179-
180168
const cdkRef = this._dialog.open<R, D, T>(componentOrTemplateRef, {
181169
...config,
182170
positionStrategy: this._overlay.position().global().centerHorizontally().centerVertically(),
@@ -264,15 +252,4 @@ export class MatDialog implements OnDestroy {
264252
dialogs[i].close();
265253
}
266254
}
267-
268-
/** Appends the given class name to the panel via the dialog config. */
269-
private _appendPanelClass(config: MatDialogConfig, className: string) {
270-
if (Array.isArray(config.panelClass)) {
271-
config.panelClass.push(className);
272-
} else if (typeof config.panelClass === 'string') {
273-
config.panelClass = [config.panelClass, className];
274-
} else {
275-
config.panelClass = className;
276-
}
277-
}
278255
}

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';
@@ -185,6 +186,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
185186
// (undocumented)
186187
protected _captureInitialFocus(): void;
187188
// (undocumented)
189+
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;
190+
// (undocumented)
188191
protected _contentAttached(): void;
189192
// (undocumented)
190193
ngOnDestroy(): void;

0 commit comments

Comments
 (0)