export const scrollIntoViewIfNeeded = ( elem , centerIfNeeded = true ) : void => { const parent = elem . parentElement ; if ( elem && parent ) { const parentComputedStyle = window . getComputedStyle ( parent , null ) ; const parentBorderTopWidth = parseInt ( parentComputedStyle . getPropertyValue ( 'border-top-width' ) , 10 ) ; const overTop = elem . offsetTop < parent . scrollTop + parentBorderTopWidth ; const overBottom = elem . offsetTop + elem . offsetHeight > parent . scrollTop + parentBorderTopWidth + parent . clientHeight ; if ( ( overTop || overBottom ) && centerIfNeeded ) { parent . scrollTop = Math . floor ( elem . offsetTop - parent . clientHeight / 2 - parentBorderTopWidth + elem . clientHeight / 2 ) ; } if ( ( overTop || overBottom ) && ! centerIfNeeded ) { if ( overBottom ) { parent . scrollTop = elem . clientHeight - ( parent . clientHeight + parentBorderTopWidth - elem . offsetTop ) ; } else { parent . scrollTop = elem . offsetTop - parentBorderTopWidth ; } } } } ;