Repository: adobe/react-spectrum
File: packages/@react-aria/utils/src/scrollIntoView.ts (TypeScript)

Code before:

  let scrollPaddingTop = parseInt(viewStyle.scrollPaddingTop, 10) || 0;
  let scrollPaddingBottom = parseInt(viewStyle.scrollPaddingBottom, 10) || 0;
  let scrollPaddingLeft = parseInt(viewStyle.scrollPaddingLeft, 10) || 0;
  let scrollPaddingRight = parseInt(viewStyle.scrollPaddingRight, 10) || 0;

  let borderTopWidth = parseInt(viewStyle.borderTopWidth, 10) || 0;
  let borderBottomWidth = parseInt(viewStyle.borderBottomWidth, 10) || 0;
  let borderLeftWidth = parseInt(viewStyle.borderLeftWidth, 10) || 0;
  let borderRightWidth = parseInt(viewStyle.borderRightWidth, 10) || 0;

  let scrollAreaTop = target.top - scrollMarginTop;
  let scrollAreaBottom = target.bottom + scrollMarginBottom;
  let scrollAreaLeft = target.left - scrollMarginLeft;
  let scrollAreaRight = target.right + scrollMarginRight;

  let scrollPortTop = viewTop + borderTopWidth + scrollPaddingTop;
  let scrollPortBottom = viewBottom - borderBottomWidth - scrollPaddingBottom;
  let scrollPortLeft = viewLeft + borderLeftWidth + scrollPaddingLeft;
  let scrollPortRight = viewRight - borderRightWidth - scrollPaddingRight;

  let shouldScrollBlock = scrollAreaTop < scrollPortTop || scrollAreaBottom > scrollPortBottom;
  let shouldScrollInline = scrollAreaLeft < scrollPortLeft || scrollAreaRight > scrollPortRight;

  if (shouldScrollBlock && block === 'start') {
    y += scrollAreaLeft - scrollPortLeft;
  } else if (shouldScrollBlock && block === 'center') {
    y += (scrollAreaTop + scrollAreaBottom) / 2 - (scrollPortTop + scrollPortBottom) / 2;
  } else if (shouldScrollBlock && block === 'end') {
    y += scrollAreaBottom - scrollPortBottom;
  } else if (shouldScrollBlock && block === 'nearest') {
    let start = scrollAreaTop - scrollPortTop;
    let end = scrollAreaBottom - scrollPortBottom;
    y += Math.abs(start) <= Math.abs(end) ? start : end;
  }

  if (shouldScrollInline && inline === 'start') {
    x += scrollAreaLeft - scrollPortLeft;
  } else if (shouldScrollInline && inline === 'center') {
    x += (scrollAreaLeft + scrollAreaRight) / 2 - (scrollPortLeft + scrollPortRight) / 2;
  } else if (shouldScrollInline && inline === 'end') {
    x += scrollAreaRight - scrollPortRight;
  } else if (shouldScrollInline && inline === 'nearest') {
    let start = scrollAreaLeft - scrollPortLeft;
    let end = scrollAreaRight - scrollPortRight;
    x += Math.abs(start) <= Math.abs(end) ? start : end;
  }

  if (process.env.NODE_ENV === 'test') {
    scrollView.scrollLeft = x;
    scrollView.scrollTop = y;

Review comment (suggestion):
typo I assume

```suggestion
    y += scrollAreaTop - scrollPortTop;
```

Code after:
  let scrollMarginBottom = parseInt(itemStyle.scrollMarginBottom, 10) || 0;
  let scrollMarginLeft = parseInt(itemStyle.scrollMarginLeft, 10) || 0;
  let scrollMarginRight = parseInt(itemStyle.scrollMarginRight, 10) || 0;

  let scrollPaddingTop = parseInt(viewStyle.scrollPaddingTop, 10) || 0;
  let scrollPaddingBottom = parseInt(viewStyle.scrollPaddingBottom, 10) || 0;
  let scrollPaddingLeft = parseInt(viewStyle.scrollPaddingLeft, 10) || 0;
  let scrollPaddingRight = parseInt(viewStyle.scrollPaddingRight, 10) || 0;

  let borderTopWidth = parseInt(viewStyle.borderTopWidth, 10) || 0;
  let borderBottomWidth = parseInt(viewStyle.borderBottomWidth, 10) || 0;
  let borderLeftWidth = parseInt(viewStyle.borderLeftWidth, 10) || 0;
  let borderRightWidth = parseInt(viewStyle.borderRightWidth, 10) || 0;

  let scrollAreaTop = target.top - scrollMarginTop;
  let scrollAreaBottom = target.bottom + scrollMarginBottom;
  let scrollAreaLeft = target.left - scrollMarginLeft;
  let scrollAreaRight = target.right + scrollMarginRight;

  let scrollPortTop = viewTop + borderTopWidth + scrollPaddingTop;
  let scrollPortBottom = viewBottom - borderBottomWidth - scrollPaddingBottom - scrollbarHeight;
  let scrollPortLeft = viewLeft + borderLeftWidth + scrollPaddingLeft;
  let scrollPortRight = viewRight - borderRightWidth - scrollPaddingRight - scrollbarWidth;

  let shouldScrollBlock = scrollAreaTop < scrollPortTop || scrollAreaBottom > scrollPortBottom;
  let shouldScrollInline = scrollAreaLeft < scrollPortLeft || scrollAreaRight > scrollPortRight;

  if (shouldScrollBlock && block === 'start') {
    y += scrollAreaTop - scrollPortTop;
  } else if (shouldScrollBlock && block === 'center') {
    y += (scrollAreaTop + scrollAreaBottom) / 2 - (scrollPortTop + scrollPortBottom) / 2;
  } else if (shouldScrollBlock && block === 'end') {
    y += scrollAreaBottom - scrollPortBottom;
  } else if (shouldScrollBlock && block === 'nearest') {
    let start = scrollAreaTop - scrollPortTop;
    let end = scrollAreaBottom - scrollPortBottom;
    y += Math.abs(start) <= Math.abs(end) ? start : end;
  }

  if (shouldScrollInline && inline === 'start') {
    x += scrollAreaLeft - scrollPortLeft;
  } else if (shouldScrollInline && inline === 'center') {
    x += (scrollAreaLeft + scrollAreaRight) / 2 - (scrollPortLeft + scrollPortRight) / 2;
  } else if (shouldScrollInline && inline === 'end') {
    x += scrollAreaRight - scrollPortRight;
  } else if (shouldScrollInline && inline === 'nearest') {
    let start = scrollAreaLeft - scrollPortLeft;
    let end = scrollAreaRight - scrollPortRight;
    x += Math.abs(start) <= Math.abs(end) ? start : end;
  }