@primer/behaviors 1.0.1-rc.c3f87ba → 1.0.1-rc.d89d4f4
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/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Shared behaviors for JavaScript components
|
|
|
10
10
|
* [Anchored Position](/docs/anchored-position.md)
|
|
11
11
|
* [Focus Trap](/docs/focus-trap.md)
|
|
12
12
|
* [Focus Zone](/docs/focus-zone.md)
|
|
13
|
-
* [Scroll Into
|
|
13
|
+
* [Scroll Into View](/docs/scroll-into-view.md)
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ScrollIntoViewOptions {
|
|
2
|
+
direction?: 'horizontal' | 'vertical';
|
|
3
|
+
startMargin?: number;
|
|
4
|
+
endMargin?: number;
|
|
5
|
+
behavior?: ScrollBehavior;
|
|
6
|
+
}
|
|
7
|
+
export declare function scrollIntoView(child: HTMLElement, viewingArea: HTMLElement, { direction, startMargin, endMargin, behavior }?: ScrollIntoViewOptions): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function scrollIntoView(child, viewingArea, { direction = 'vertical', startMargin = 8, 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';
|
|
@@ -14,4 +14,4 @@ export const scrollIntoViewingArea = (child, viewingArea, direction = 'vertical'
|
|
|
14
14
|
const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
|
|
15
15
|
viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildBottom + startMargin });
|
|
16
16
|
}
|
|
17
|
-
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const scrollIntoViewingArea: (child: HTMLElement, viewingArea: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
|