Skip to content

Commit 2a7bb42

Browse files
committed
fix: respect animation:false option to disable modal animations
Fixes #1010 - Previously, setting animation to false had no effect because the animation was hardcoded in CSS. This change: - Adds 'animation' as a proper SwalOptions property (boolean, default: true) - When animation is false, adds 'swal-modal--no-animation' class to modal - CSS rule disables all animations when this class is present - Removes deprecation warning for the animation option
1 parent d927c9b commit 2a7bb42

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/modules/init/modal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ const resetModalElement = (modal: Element): void => {
3535
const customizeModalElement = (modal: Element, opts: SwalOptions): void => {
3636
resetModalElement(modal);
3737

38-
const { className } = opts;
38+
const { className, animation } = opts;
3939

4040
if (className) {
4141
modal.classList.add(className);
4242
}
43+
44+
if (animation === false) {
45+
modal.classList.add('swal-modal--no-animation');
46+
}
4347
};
4448

4549
/*

src/modules/options/deprecations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export const DEPRECATED_OPTS: OptionReplacementsList = {
8383
'showLoaderOnConfirm': {
8484
replacement: 'buttons',
8585
},
86-
'animation': {},
8786
'inputType': {
8887
replacement: 'content',
8988
link: '/docs/#content',

src/modules/options/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface SwalOptions {
3737
closeOnEsc: boolean,
3838
dangerMode: boolean,
3939
timer: number,
40+
animation: boolean,
4041
};
4142

4243
const defaultOpts: SwalOptions = {
@@ -50,6 +51,7 @@ const defaultOpts: SwalOptions = {
5051
closeOnEsc: true,
5152
dangerMode: false,
5253
timer: null,
54+
animation: true,
5355
};
5456

5557
/*

src/sweetalert.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
animation: showSweetAlert 0.3s;
4242
will-change: transform;
4343
}
44+
45+
& .swal-modal.swal-modal--no-animation {
46+
animation: none;
47+
}
4448
}
4549
}
4650

@@ -113,3 +117,14 @@ Target IE8-IE10 due to incompability with the css `pointer-event` property.
113117
visibility: hidden;
114118
}
115119
}
120+
121+
/* Disable animation when animation option is false */
122+
.swal-overlay--show-modal .swal-modal.swal-modal--no-animation {
123+
animation: none;
124+
}
125+
126+
.swal-modal--no-animation .swal-icon--success__line,
127+
.swal-modal--no-animation .swal-icon--error__x-mark,
128+
.swal-modal--no-animation .swal-icon--warning {
129+
animation: none;
130+
}

0 commit comments

Comments
 (0)