|
22 | 22 |
|
23 | 23 | let { open, onClose, ...rest }: Props = $props() |
24 | 24 |
|
25 | | - // iOS-strength body scroll lock while the drawer is open. The |
26 | | - // weaker `overflow: hidden` version still let iOS interpret touch- |
27 | | - // scroll attempts as "page wants to scroll", which collapses the |
28 | | - // address bar and re-flows the visual viewport — visibly bouncing |
29 | | - // the drawer's bottom tab bar as the chub results list reaches its |
30 | | - // scroll edge. Pinning body to `position: fixed` actually anchors |
31 | | - // the layout so the address bar stops collapsing/expanding on |
32 | | - // touch. We capture the current scrollY into `top: -<y>px` and |
33 | | - // restore both on close, so the user lands exactly where they |
34 | | - // started behind the drawer. |
| 25 | + // Lock body scroll while the drawer is open. Prevents iOS Safari |
| 26 | + // from rubber-banding the document when an inner scroll hits its |
| 27 | + // edge. The earlier `position: fixed` variant broke inner scrolling |
| 28 | + // entirely; `overflow: hidden` is the minimum that still lets the |
| 29 | + // drawer's overflow-y-auto regions scroll normally. |
35 | 30 | $effect(() => { |
36 | 31 | if (typeof document === 'undefined') return |
37 | 32 | if (!open) return |
38 | | - const body = document.body |
39 | | - const prev = { |
40 | | - position: body.style.position, |
41 | | - top: body.style.top, |
42 | | - left: body.style.left, |
43 | | - right: body.style.right, |
44 | | - width: body.style.width, |
45 | | - overflow: body.style.overflow, |
46 | | - } |
47 | | - const scrollY = window.scrollY |
48 | | - body.style.position = 'fixed' |
49 | | - body.style.top = `-${scrollY}px` |
50 | | - body.style.left = '0' |
51 | | - body.style.right = '0' |
52 | | - body.style.width = '100%' |
53 | | - body.style.overflow = 'hidden' |
54 | | - return () => { |
55 | | - body.style.position = prev.position |
56 | | - body.style.top = prev.top |
57 | | - body.style.left = prev.left |
58 | | - body.style.right = prev.right |
59 | | - body.style.width = prev.width |
60 | | - body.style.overflow = prev.overflow |
61 | | - window.scrollTo(0, scrollY) |
62 | | - } |
| 33 | + const prev = document.body.style.overflow |
| 34 | + document.body.style.overflow = 'hidden' |
| 35 | + return () => { document.body.style.overflow = prev } |
63 | 36 | }) |
64 | 37 | </script> |
65 | 38 |
|
|
0 commit comments