Skip to content

Commit 32a8b38

Browse files
authored
fix(cdk/dialog): add container structural styles (#24905)
Currently the CDK dialog container doesn't come with any styles which means that it's `display: inline`, making it difficult to change its size. These changes add a handful of styles to make it match the specified size in the config.
1 parent 567be4f commit 32a8b38

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

src/cdk/dialog/BUILD.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load(
44
"ng_module",
55
"ng_test_library",
66
"ng_web_test_suite",
7+
"sass_binary",
78
)
89

910
package(default_visibility = ["//visibility:public"])
@@ -14,7 +15,7 @@ ng_module(
1415
["**/*.ts"],
1516
exclude = ["**/*.spec.ts"],
1617
),
17-
assets = glob(["**/*.html"]),
18+
assets = [":dialog-container.css"] + glob(["**/*.html"]),
1819
deps = [
1920
"//src:dev_mode_types",
2021
"//src/cdk/a11y",
@@ -61,3 +62,8 @@ filegroup(
6162
name = "source-files",
6263
srcs = glob(["**/*.ts"]),
6364
)
65+
66+
sass_binary(
67+
name = "dialog_container_scss",
68+
src = "dialog-container.scss",
69+
)

src/cdk/dialog/dialog-container.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.cdk-dialog-container {
2+
// The container is a custom node so it'll be `display: inline` by default.
3+
display: block;
4+
5+
// The dialog container should completely fill its parent overlay element.
6+
width: 100%;
7+
height: 100%;
8+
9+
// Since the dialog won't stretch to fit the parent, if the height
10+
// isn't set, we have to inherit the min and max values explicitly.
11+
min-height: inherit;
12+
max-height: inherit;
13+
}

src/cdk/dialog/dialog-container.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function throwDialogContentAlreadyAttachedError() {
4949
@Component({
5050
selector: 'cdk-dialog-container',
5151
templateUrl: './dialog-container.html',
52+
styleUrls: ['dialog-container.css'],
5253
encapsulation: ViewEncapsulation.None,
5354
// Using OnPush for dialogs caused some G3 sync issues. Disabled until we can track them down.
5455
// tslint:disable-next-line:validate-decorators

src/dev-app/cdk-dialog/dialog-demo.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
.demo-cdk-dialog {
2-
background: white;
3-
padding: 20px;
4-
border-radius: 8px;
5-
}
6-
71
.demo-container {
82
button, label {
93
margin-right: 8px;

src/dev-app/cdk-dialog/dialog-demo.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,24 @@ export class DialogDemo {
7575
<button (click)="temporarilyHide()">Hide for 2 seconds</button>
7676
</div>
7777
`,
78-
encapsulation: ViewEncapsulation.None,
79-
styles: [`.hidden-dialog { opacity: 0; }`],
78+
styles: [
79+
`
80+
:host {
81+
background: white;
82+
padding: 20px;
83+
border-radius: 8px;
84+
display: block;
85+
width: 100%;
86+
height: 100%;
87+
min-width: inherit;
88+
min-height: inherit;
89+
}
90+
91+
:host-context(.hidden-dialog) {
92+
opacity: 0;
93+
}
94+
`,
95+
],
8096
standalone: true,
8197
})
8298
export class JazzDialog {

0 commit comments

Comments
 (0)