Skip to content

Commit 16f4725

Browse files
committed
fix: apply overflow: hidden style when transitioning elements, where necessary
1 parent 7737868 commit 16f4725

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/sixty-paws-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: apply `overflow: hidden` style when transitioning elements, where necessary

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export function transition(flags, element, get_fn, get_params) {
192192

193193
var inert = element.inert;
194194

195+
var overflow = element.style.overflow;
196+
195197
/** @type {Animation | undefined} */
196198
var intro;
197199

@@ -242,6 +244,8 @@ export function transition(flags, element, get_fn, get_params) {
242244
// Ensure we cancel the animation to prevent leaking
243245
intro?.abort();
244246
intro = current_options = undefined;
247+
248+
element.style.overflow = overflow;
245249
});
246250
},
247251
out(fn) {
@@ -382,16 +386,24 @@ function animate(element, options, counterpart, t2, on_finish) {
382386
var keyframes = [];
383387

384388
if (duration > 0) {
389+
var needs_overflow_hidden = false;
390+
385391
if (css) {
386392
var n = Math.ceil(duration / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
387393

388394
for (var i = 0; i <= n; i += 1) {
389395
var t = t1 + delta * easing(i / n);
390-
var styles = css(t, 1 - t);
391-
keyframes.push(css_to_keyframe(styles));
396+
var styles = css_to_keyframe(css(t, 1 - t));
397+
keyframes.push(styles);
398+
399+
needs_overflow_hidden ||= styles.overflow === 'hidden';
392400
}
393401
}
394402

403+
if (needs_overflow_hidden) {
404+
/** @type {HTMLElement} */ (element).style.overflow = 'hidden';
405+
}
406+
395407
get_t = () => {
396408
var time = /** @type {number} */ (
397409
/** @type {globalThis.Animation} */ (animation).currentTime

0 commit comments

Comments
 (0)