Skip to content

Commit 79e0b7f

Browse files
feat(dialog): add dialog container slot
PiperOrigin-RevId: 721930993
1 parent ac91657 commit 79e0b7f

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

dialog/internal/_dialog.scss

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@
157157
position: absolute;
158158
}
159159

160+
.container-slot {
161+
border-radius: inherit;
162+
inset: 0;
163+
position: absolute;
164+
}
165+
166+
slot[name='container'] {
167+
border-radius: inherit;
168+
}
169+
160170
.scroller {
161171
display: flex;
162172
flex: 1;

dialog/internal/animations.ts

+36
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export interface DialogAnimation {
2626
*/
2727
scrim?: DialogAnimationArgs[];
2828

29+
/**
30+
* Animations for the container slot.
31+
*/
32+
containerSlot?: DialogAnimationArgs[];
33+
2934
/**
3035
* Animations for the container of the dialog.
3136
*/
@@ -64,6 +69,22 @@ export const DIALOG_DEFAULT_OPEN_ANIMATION: DialogAnimation = {
6469
{duration: 500, easing: 'linear'},
6570
],
6671
],
72+
containerSlot: [
73+
[
74+
// Container slot fade in
75+
[{'opacity': 0}, {'opacity': 1}],
76+
{duration: 50, easing: 'linear'},
77+
],
78+
[
79+
// Container slot grow
80+
// Note: current spec says to grow from 0dp->100% and shrink from
81+
// 100%->35%. We change this to 35%->100% to simplify the animation that
82+
// is supposed to clip content as it grows. From 0dp it's possible to see
83+
// text/actions appear before the container has fully grown.
84+
[{'height': '35%'}, {'height': '100%'}],
85+
{duration: 500, easing: EASING.EMPHASIZED},
86+
],
87+
],
6788
container: [
6889
[
6990
// Container fade in
@@ -121,6 +142,21 @@ export const DIALOG_DEFAULT_CLOSE_ANIMATION: DialogAnimation = {
121142
{duration: 150, easing: 'linear'},
122143
],
123144
],
145+
containerSlot: [
146+
[
147+
// Container slot shrink
148+
[{'height': '100%'}, {'height': '35%'}],
149+
{
150+
duration: 150,
151+
easing: EASING.EMPHASIZED_ACCELERATE,
152+
},
153+
],
154+
[
155+
// Container slot fade out
156+
[{'opacity': '1'}, {'opacity': '0'}],
157+
{delay: 100, duration: 50, easing: 'linear'},
158+
],
159+
],
124160
container: [
125161
[
126162
// Container shrink

dialog/internal/dialog.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export class Dialog extends dialogBaseClass {
115115
private isConnectedPromise = this.getIsConnectedPromise();
116116
@query('dialog') private readonly dialog!: HTMLDialogElement | null;
117117
@query('.scrim') private readonly scrim!: HTMLDialogElement | null;
118+
@query('.container-slot')
119+
private readonly containerSlot!: HTMLDialogElement | null;
118120
@query('.container') private readonly container!: HTMLDialogElement | null;
119121
@query('.headline') private readonly headline!: HTMLDialogElement | null;
120122
@query('.content') private readonly content!: HTMLDialogElement | null;
@@ -301,6 +303,9 @@ export class Dialog extends dialogBaseClass {
301303
@keydown=${this.handleKeydown}
302304
.returnValue=${this.returnValue || nothing}>
303305
${showFocusTrap ? focusTrap : nothing}
306+
<div class="container-slot">
307+
<slot name="container"></slot>
308+
</div>
304309
<div class="container" @click=${this.handleContentClick}>
305310
<div class="headline">
306311
<div class="icon" aria-hidden="true">
@@ -433,13 +438,30 @@ export class Dialog extends dialogBaseClass {
433438
return;
434439
}
435440

436-
const {dialog, scrim, container, headline, content, actions} = this;
437-
if (!dialog || !scrim || !container || !headline || !content || !actions) {
441+
const {
442+
dialog,
443+
scrim,
444+
containerSlot,
445+
container,
446+
headline,
447+
content,
448+
actions,
449+
} = this;
450+
if (
451+
!dialog ||
452+
!scrim ||
453+
!containerSlot ||
454+
!container ||
455+
!headline ||
456+
!content ||
457+
!actions
458+
) {
438459
return;
439460
}
440461

441462
const {
442463
container: containerAnimate,
464+
containerSlot: containerSlotAnimate,
443465
dialog: dialogAnimate,
444466
scrim: scrimAnimate,
445467
headline: headlineAnimate,
@@ -450,6 +472,7 @@ export class Dialog extends dialogBaseClass {
450472
const elementAndAnimation: Array<[Element, DialogAnimationArgs[]]> = [
451473
[dialog, dialogAnimate ?? []],
452474
[scrim, scrimAnimate ?? []],
475+
[containerSlot, containerSlotAnimate ?? []],
453476
[container, containerAnimate ?? []],
454477
[headline, headlineAnimate ?? []],
455478
[content, contentAnimate ?? []],

0 commit comments

Comments
 (0)