Skip to content

Commit b9978ca

Browse files
committed
fix: Fixed SwappablePlugin style on undefined element error
1 parent 863e3e1 commit b9978ca

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"editor.formatOnSave": true,
2020
"editor.codeActionsOnSave": {
21-
"source.fixAll.eslint": true
21+
"source.fixAll.eslint": "explicit"
2222
},
2323
"javascript.validate.enable": false,
2424
"eslint.validate": ["javascript"]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@
9393
"last 3 chromeandroid versions",
9494
"last 1 firefoxandroid versions",
9595
"ios >= 13.4"
96-
]
96+
],
97+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
9798
}

src/Plugins/SwapAnimation/SwapAnimation.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,33 @@ function animate(
121121
{duration, easingFunction, horizontal}: Options,
122122
) {
123123
for (const element of [from, to]) {
124-
element.style.pointerEvents = 'none';
124+
if (!element || !element.style) {
125+
// eslint-disable-next-line no-console
126+
console.warn('Element is not HTMLElement', element);
127+
}
128+
if (element && element.style) {
129+
element.style.pointerEvents = 'none';
130+
}
125131
}
126-
127-
if (horizontal) {
128-
const width = from.offsetWidth;
129-
from.style.transform = `translate3d(${width}px, 0, 0)`;
130-
to.style.transform = `translate3d(-${width}px, 0, 0)`;
131-
} else {
132-
const height = from.offsetHeight;
133-
from.style.transform = `translate3d(0, ${height}px, 0)`;
134-
to.style.transform = `translate3d(0, -${height}px, 0)`;
132+
if (from && to && from.style && to.style) {
133+
if (horizontal) {
134+
const width = from.offsetWidth;
135+
from.style.transform = `translate3d(${width}px, 0, 0)`;
136+
to.style.transform = `translate3d(-${width}px, 0, 0)`;
137+
} else {
138+
const height = from.offsetHeight;
139+
from.style.transform = `translate3d(0, ${height}px, 0)`;
140+
to.style.transform = `translate3d(0, -${height}px, 0)`;
141+
}
135142
}
136143

137144
requestAnimationFrame(() => {
138145
for (const element of [from, to]) {
139-
element.addEventListener('transitionend', resetElementOnTransitionEnd);
140-
element.style.transition = `transform ${duration}ms ${easingFunction}`;
141-
element.style.transform = '';
146+
if (element && element.style && element.addEventListener) {
147+
element.addEventListener('transitionend', resetElementOnTransitionEnd);
148+
element.style.transition = `transform ${duration}ms ${easingFunction}`;
149+
element.style.transform = '';
150+
}
142151
}
143152
});
144153
}

0 commit comments

Comments
 (0)