Skip to content

Commit 84762e6

Browse files
authored
UX: Modal close animation (#32842)
Adding an animation on closing the modal.
1 parent 648722d commit 84762e6

File tree

1 file changed

+36
-0
lines changed
  • app/assets/javascripts/discourse/app/components

1 file changed

+36
-0
lines changed

app/assets/javascripts/discourse/app/components/d-modal.gjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ export default class DModal extends Component {
193193
this.animating = false;
194194
}
195195

196+
if (this.site.desktopView) {
197+
try {
198+
this.animating = true;
199+
await this.#animatePopOff();
200+
} finally {
201+
this.animating = false;
202+
}
203+
}
204+
196205
this.args.closeModal({ initiatedBy });
197206
}
198207

@@ -264,6 +273,33 @@ export default class DModal extends Component {
264273
).finished;
265274
}
266275

276+
async #animatePopOff() {
277+
const backdrop = this.wrapperElement.nextElementSibling;
278+
279+
if (!backdrop) {
280+
return;
281+
}
282+
283+
await Promise.all([
284+
this.modalContainer.animate(
285+
[
286+
{ transform: "scale(1)", opacity: 1, offset: 0 },
287+
{ transform: "scale(0)", opacity: 0, offset: 1 },
288+
],
289+
{
290+
fill: "forwards",
291+
duration: getMaxAnimationTimeMs(300),
292+
easing: "cubic-bezier(0.4, 0, 0.2, 1)",
293+
}
294+
).finished,
295+
backdrop.animate([{ opacity: 0.6 }, { opacity: 0 }], {
296+
fill: "forwards",
297+
duration: getMaxAnimationTimeMs(300),
298+
easing: "cubic-bezier(0.4, 0, 0.2, 1)",
299+
}).finished,
300+
]);
301+
}
302+
267303
<template>
268304
{{! template-lint-disable no-invalid-interactive }}
269305

0 commit comments

Comments
 (0)