File tree Expand file tree Collapse file tree 3 files changed +29
-15
lines changed
packages/site-kit/src/lib Expand file tree Collapse file tree 3 files changed +29
-15
lines changed Original file line number Diff line number Diff line change 1
1
import { page } from '$app/stores' ;
2
2
import { persisted } from 'svelte-persisted-store' ;
3
3
import { get } from 'svelte/store' ;
4
+ import { fix_position } from './utils' ;
4
5
5
6
const show_legacy = persisted ( 'svelte:show-legacy' , true ) ;
6
7
@@ -30,20 +31,13 @@ export function legacy_details(node: HTMLElement) {
30
31
31
32
show_legacy . set ( detail . open ) ;
32
33
33
- const top = detail . getBoundingClientRect ( ) . top ;
34
-
35
- for ( const other of details ) {
36
- if ( other !== detail ) {
37
- other . open = detail . open ;
34
+ fix_position ( detail , ( ) => {
35
+ for ( const other of details ) {
36
+ if ( other !== detail ) {
37
+ other . open = detail . open ;
38
+ }
38
39
}
39
- }
40
-
41
- const delta = detail . getBoundingClientRect ( ) . top - top ;
42
-
43
- if ( delta !== 0 ) {
44
- // whichever element the user interacted with should stay in the same position
45
- ( scroll_parent ?? document . body ) . scrollBy ( 0 , delta ) ;
46
- }
40
+ } ) ;
47
41
48
42
setTimeout ( ( ) => {
49
43
secondary = false ;
Original file line number Diff line number Diff line change
1
+ export function fix_position ( element : HTMLElement , fn : Function ) {
2
+ let scroll_parent : HTMLElement | null = element ;
3
+
4
+ while ( ( scroll_parent = scroll_parent . parentElement ) ) {
5
+ if ( / ^ ( s c r o l l | a u t o ) $ / . test ( getComputedStyle ( scroll_parent ) . overflowY ) ) {
6
+ break ;
7
+ }
8
+ }
9
+
10
+ const top = element . getBoundingClientRect ( ) . top ;
11
+ fn ( ) ;
12
+ const delta = element . getBoundingClientRect ( ) . top - top ;
13
+
14
+ if ( delta !== 0 ) {
15
+ // whichever element the user interacted with should stay in the same position
16
+ ( scroll_parent ?? window ) . scrollBy ( 0 , delta ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change 2
2
import { afterNavigate } from ' $app/navigation' ;
3
3
import type { Snippet } from ' svelte' ;
4
4
import { prefers_ts } from ' ../stores/prefers_ts' ;
5
+ import { fix_position } from ' ../actions/utils' ;
5
6
6
7
let { children }: { children: Snippet } = $props ();
7
8
19
20
20
21
function toggle(e : Event ) {
21
22
if ((e .target as HTMLElement ).classList .contains (' ts-toggle' )) {
22
- $prefers_ts = (e .target as HTMLInputElement ).checked ;
23
- update ();
23
+ const input = e .target as HTMLInputElement ;
24
+ $prefers_ts = input .checked ;
25
+ fix_position (input , update );
24
26
}
25
27
}
26
28
You can’t perform that action at this time.
0 commit comments