Skip to content

Commit cac7a41

Browse files
authored
fix(material/dialog): css structure change (#27510)
* fix(material/dialog): css structure change * change the css structure of the dialog surface and it's children * fixup! fix(material/dialog): css structure change * fixup! fix(material/dialog): css structure change * fixup! fix(material/dialog): css structure change * fixup! fix(material/dialog): css structure change * fixup! fix(material/dialog): css structure change
1 parent 8eb494e commit cac7a41

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-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 its host with the `mat-mdc-dialog-component-host` 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-host {
56+
display: contents;
57+
}
5658
}

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: contents` 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';

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';
@@ -183,6 +184,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
183184
_animationsEnabled: boolean;
184185
_animationStateChanged: EventEmitter<LegacyDialogAnimationEvent>;
185186
// (undocumented)
187+
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T>;
188+
// (undocumented)
186189
protected _captureInitialFocus(): void;
187190
// (undocumented)
188191
protected _contentAttached(): void;

0 commit comments

Comments
 (0)