Skip to content

Commit bf80996

Browse files
committed
fix(material/dialog): css structure change
* change the css structure of the dialog surface and it's children
1 parent 5f190b3 commit bf80996

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@
3838
max-width: inherit;
3939
}
4040

41-
// MDC by default sets the `surface` to `display: flex`. MDC does this in order to
42-
// be able to make the content scrollable while locking the title and actions. This
43-
// does not work in our dialog anyway because due to the content projection, arbitrary
44-
// components can be immediate children of the surface and make this a noop. If only
45-
// templates or DOM elements are projected, the flex display could cause unexpected
46-
// alignment issues as explained in our coding standards (see `CODING_STANDARDS.md`).
47-
// Additionally, the surface by default should expand based on the parent overlay
48-
// boundaries (so that boundaries for the overlay config are respected). The surface
49-
// by default would only expand based on its content.
5041
.mdc-dialog__surface {
51-
display: block;
5242
width: 100%;
5343
height: 100%;
5444
}
5545
}
46+
47+
// When a component is passed into the dialog, the host element interrupts
48+
// the `display:flex` from affecting the dialog title, content, and
49+
// actions. To fix this, we make the component host `display: contents` by
50+
// marking it's panel with the `mat-mdc-dialog-component-panel` class.
51+
//
52+
// Note that this problem does not exist when a template ref is used since
53+
// the title, contents, and actions are then nested directly under the
54+
// dialog surface.
55+
.mat-mdc-dialog-component-panel .mat-mdc-dialog-surface > * {
56+
display: contents;
57+
}
5658
}

src/material/dialog/dialog.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ 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: contents` 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+
165177
const cdkRef = this._dialog.open<R, D, T>(componentOrTemplateRef, {
166178
...config,
167179
positionStrategy: this._overlay.position().global().centerHorizontally().centerVertically(),
@@ -249,6 +261,17 @@ export abstract class _MatDialogBase<C extends _MatDialogContainerBase> implemen
249261
dialogs[i].close();
250262
}
251263
}
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+
}
252275
}
253276

254277
/**

0 commit comments

Comments
 (0)