@primer/behaviors 1.0.1-rc.d89d4f4 → 1.0.2-rc.b89e9b4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # @primer/behaviors
2
2
 
3
- ## 1.0.1
3
+ ## 1.0.2
4
+
4
5
  ### Patch Changes
5
6
 
7
+ - [#17](https://github.com/primer/behaviors/pull/17) [`9194ba4`](https://github.com/primer/behaviors/commit/9194ba403502b4acba0be03bed1a765c1ba81340) Thanks [@dgreif](https://github.com/dgreif)! - Correct margin orientation for `scrollIntoView`
8
+
9
+ * [#18](https://github.com/primer/behaviors/pull/18) [`3b4dd41`](https://github.com/primer/behaviors/commit/3b4dd414175417f83bd144939fe74b2a01bc7136) Thanks [@dgreif](https://github.com/dgreif)! - Export utils as submodule
6
10
 
11
+ ## 1.0.1
12
+
13
+ ### Patch Changes
7
14
 
8
15
  - [#10](https://github.com/primer/behaviors/pull/10) [`88b6f34`](https://github.com/primer/behaviors/commit/88b6f34bf4874f3c81473020a01a58b197dd6e16) Thanks [@dgreif](https://github.com/dgreif)! - Set up changesets
@@ -1,17 +1,17 @@
1
- export function scrollIntoView(child, viewingArea, { direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth' } = {}) {
1
+ export function scrollIntoView(child, viewingArea, { direction = 'vertical', startMargin = 0, endMargin = 0, behavior = 'smooth' } = {}) {
2
2
  const startSide = direction === 'vertical' ? 'top' : 'left';
3
3
  const endSide = direction === 'vertical' ? 'bottom' : 'right';
4
4
  const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
5
5
  const { [startSide]: childStart, [endSide]: childEnd } = child.getBoundingClientRect();
6
6
  const { [startSide]: viewingAreaStart, [endSide]: viewingAreaEnd } = viewingArea.getBoundingClientRect();
7
- const isChildStartAboveViewingArea = childStart < viewingAreaStart + endMargin;
8
- const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - startMargin;
7
+ const isChildStartAboveViewingArea = childStart < viewingAreaStart + startMargin;
8
+ const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - endMargin;
9
9
  if (isChildStartAboveViewingArea) {
10
10
  const scrollHeightToChildStart = childStart - viewingAreaStart + viewingArea[scrollSide];
11
- viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildStart - endMargin });
11
+ viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildStart - startMargin });
12
12
  }
13
13
  else if (isChildBottomBelowViewingArea) {
14
14
  const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
15
- viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildBottom + startMargin });
15
+ viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildBottom + endMargin });
16
16
  }
17
17
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "1.0.1-rc.d89d4f4",
3
+ "version": "1.0.2-rc.b89e9b4",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [
9
- "dist"
9
+ "dist",
10
+ "utils"
10
11
  ],
11
12
  "sideEffects": [
12
13
  "dist/focus-zone.js",
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@primer/behaviors/utils",
3
+ "types": "../dist/utils/index.d.ts",
4
+ "main": "../dist/utils/index.js",
5
+ "type": "module",
6
+ "sideEffects": false
7
+ }