-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!(deps): remove smooth scroll polyfill. Determined that brows…
…er support is sufficient that polyfilling is no longer needed. Any users needing the polyfill should include the polyfill itself.
- Loading branch information
Showing
3 changed files
with
64 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,62 @@ | ||
import smoothScroll from 'smoothscroll-polyfill'; | ||
|
||
export async function scrollToElement(element: Element, {behavior = "smooth", block = "start", inline = "nearest"}: ScrollIntoViewOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollIntoView({behavior, block, inline}); | ||
} | ||
|
||
export async function scrollAbsoluteTop(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollTo({top: 0, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollAbsoluteBottom(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
if (element == window) { | ||
element.scrollTo({top: document.body.scrollHeight, left: 0, behavior}); | ||
} else { | ||
element.scrollTo({top: (element as Element).scrollHeight, left: 0, behavior}); | ||
} | ||
} | ||
|
||
export async function scrollAbsoluteLeft(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollTo({left: 0, behavior}); | ||
} | ||
|
||
export async function scrollAbsoluteRight(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
if (element == window) { | ||
element.scrollTo({left: document.body.scrollWidth, behavior}); | ||
} else { | ||
element.scrollTo({left: (element as Element).scrollWidth, behavior}); | ||
} | ||
} | ||
|
||
export async function scrollUp(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollBy({top: -amount, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollDown(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollBy({top: amount, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollLeft(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollBy({top: 0, left: -amount, behavior}); | ||
} | ||
|
||
export async function scrollRight(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
smoothScroll.polyfill(); | ||
element.scrollBy({top: 0, left: amount, behavior}); | ||
} | ||
|
||
export function getScrollParent(node: HTMLElement | null): Window | HTMLElement | null { | ||
smoothScroll.polyfill(); | ||
if (!node) { | ||
return null; | ||
} | ||
|
||
if (node == document.body) { | ||
return window; | ||
} | ||
|
||
const overflowY = getComputedStyle(node).overflowY; | ||
const isScrollable = overflowY !== "visible" && overflowY !== "hidden"; | ||
|
||
if (isScrollable && node.scrollHeight >= node.clientHeight) { | ||
return node; | ||
} | ||
|
||
return getScrollParent(node.parentElement) || document.body; | ||
} | ||
export async function scrollToElement(element: Element, {behavior = "smooth", block = "start", inline = "nearest"}: ScrollIntoViewOptions = {}) { | ||
element.scrollIntoView({behavior, block, inline}); | ||
} | ||
|
||
export async function scrollAbsoluteTop(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollTo({top: 0, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollAbsoluteBottom(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
if (element == window) { | ||
element.scrollTo({top: document.body.scrollHeight, left: 0, behavior}); | ||
} else { | ||
element.scrollTo({top: (element as Element).scrollHeight, left: 0, behavior}); | ||
} | ||
} | ||
|
||
export async function scrollAbsoluteLeft(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollTo({left: 0, behavior}); | ||
} | ||
|
||
export async function scrollAbsoluteRight(element: Window | Element, {behavior = "smooth"}: ScrollOptions = {}) { | ||
if (element == window) { | ||
element.scrollTo({left: document.body.scrollWidth, behavior}); | ||
} else { | ||
element.scrollTo({left: (element as Element).scrollWidth, behavior}); | ||
} | ||
} | ||
|
||
export async function scrollUp(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollBy({top: -amount, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollDown(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollBy({top: amount, left: 0, behavior}); | ||
} | ||
|
||
export async function scrollLeft(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollBy({top: 0, left: -amount, behavior}); | ||
} | ||
|
||
export async function scrollRight(element: Window | Element, amount: number, {behavior = "smooth"}: ScrollOptions = {}) { | ||
element.scrollBy({top: 0, left: amount, behavior}); | ||
} | ||
|
||
export function getScrollParent(node: HTMLElement | null): Window | HTMLElement | null { | ||
if (!node) { | ||
return null; | ||
} | ||
|
||
if (node == document.body) { | ||
return window; | ||
} | ||
|
||
const overflowY = getComputedStyle(node).overflowY; | ||
const isScrollable = overflowY !== "visible" && overflowY !== "hidden"; | ||
|
||
if (isScrollable && node.scrollHeight >= node.clientHeight) { | ||
return node; | ||
} | ||
|
||
return getScrollParent(node.parentElement) || document.body; | ||
} |