@shopify/shop-minis-react
Version:
React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)
27 lines (20 loc) • 777 B
text/typescript
// For finding the scrollable element within a container for pull-to-refresh functionality.
export const findVirtuosoScrollableElement = (
container: HTMLElement
): HTMLElement => {
const selector = '[data-virtuoso-scroller]'
let scrollableElement: HTMLElement | null = null
scrollableElement = container.querySelector(selector) as HTMLElement
if (scrollableElement) return scrollableElement
if (!scrollableElement) {
const allDivs = Array.from(container.querySelectorAll('div'))
for (const div of allDivs) {
const style = window.getComputedStyle(div)
if (style.overflowY === 'auto' || style.overflowY === 'scroll') {
scrollableElement = div as HTMLElement
break
}
}
}
return scrollableElement || container
}