# All files / src/_utils scrollIntoView.ts

64.28% Statements 9/14
20% Branches 1/5
100% Functions 1/1
58.33% Lines 7/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    2236x
    82x

    82x

    164x

    82x

    82x

    82x

     export function scrollIntoView(index: number, element: HTMLElement) {
      Iif (!element.parentElement) {
        return
      }

      Iif (index === 0) {
        element.parentElement.scrollTop = 0

        return
      }

      const { offsetTop, clientHeight } = element

      const { scrollTop, clientHeight: parentHeight } = element.parentElement

      Iif (offsetTop < scrollTop) {
        element.parentElement.scrollTop = offsetTop
      } else Iif (offsetTop + clientHeight > scrollTop + parentHeight) {
        element.parentElement.scrollTop = offsetTop - parentHeight + clientHeight
      }
    }