@@ -16,58 +16,59 @@ const browserOverlay = ['safari-light', 'safari-dark'].reduce(
1616 { }
1717)
1818
19- const isOverflown = element => {
20- return element . scrollHeight > element . clientHeight || element . scrollWidth > element . clientWidth
21- }
22-
23- const findScrollParent = element => {
24- if ( element === undefined ) {
25- return
26- }
27- if ( isOverflown ( element ) ) {
28- return element
19+ const scrollToElement = ( element , options ) => {
20+ const isOverflown = element => {
21+ return element . scrollHeight > element . clientHeight || element . scrollWidth > element . clientWidth
2922 }
3023
31- return findScrollParent ( element . parentElement )
32- }
24+ const findScrollParent = element => {
25+ if ( element === undefined ) {
26+ return
27+ }
3328
34- const calculateOffset = ( rect , options ) => {
35- if ( options === undefined ) {
36- return {
37- x : rect . left ,
38- y : rect . top
29+ if ( isOverflown ( element ) ) {
30+ return element
3931 }
40- }
4132
42- const offset = options . offset || 0
33+ return findScrollParent ( element . parentElement )
34+ }
4335
44- switch ( options . offsetFrom ) {
45- case 'top' :
36+ const calculateOffset = ( rect , options ) => {
37+ if ( options === undefined ) {
4638 return {
4739 x : rect . left ,
48- y : rect . top + offset
49- }
50- case 'right' :
51- return {
52- x : rect . left - offset ,
5340 y : rect . top
5441 }
55- case 'bottom' :
56- return {
57- x : rect . left ,
58- y : rect . top - offset
59- }
60- case 'left' :
61- return {
62- x : rect . left + offset ,
63- y : rect . top
64- }
65- default :
66- throw new Error ( 'Invalid `scrollToElement.offsetFrom` value' )
42+ }
43+
44+ const offset = options . offset || 0
45+
46+ switch ( options . offsetFrom ) {
47+ case 'top' :
48+ return {
49+ x : rect . left ,
50+ y : rect . top + offset
51+ }
52+ case 'right' :
53+ return {
54+ x : rect . left - offset ,
55+ y : rect . top
56+ }
57+ case 'bottom' :
58+ return {
59+ x : rect . left ,
60+ y : rect . top - offset
61+ }
62+ case 'left' :
63+ return {
64+ x : rect . left + offset ,
65+ y : rect . top
66+ }
67+ default :
68+ throw new Error ( 'Invalid `scrollToElement.offsetFrom` value' )
69+ }
6770 }
68- }
6971
70- const scrollToElement = ( element , options ) => {
7172 const rect = element . getBoundingClientRect ( )
7273 const offset = calculateOffset ( rect , options )
7374 const parent = findScrollParent ( element )
0 commit comments