Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/FilteredActionList/FilteredActionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {itemActiveDescendantClass} from '../ActionList/Item'
import {useProvidedStateOrCreate} from '../hooks/useProvidedStateOrCreate'
import styled from 'styled-components'
import {get} from '../constants'
import useScrollFlash from '../hooks/useScrollFlash'

export interface FilteredActionListProps extends Partial<Omit<GroupedListProps, keyof ListPropsBase>>, ListPropsBase {
loading?: boolean
Expand Down Expand Up @@ -121,6 +122,8 @@ export function FilteredActionList({
}
}, [items])

useScrollFlash(scrollContainerRef)

return (
<Flex ref={containerRef} flexDirection="column" overflow="hidden">
<StyledHeader>
Expand Down
21 changes: 21 additions & 0 deletions src/hooks/useScrollFlash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, {useEffect} from 'react'
/**
* This hook will flash the scrollbars for a ref of a container that has scrollable overflow
* @param scrollContainerRef The ref of the scrollable content
*/
export default function useScrollFlash(scrollContainerRef: React.RefObject<HTMLElement>) {
// https://adxlv.computer/projects/flash-scrollers/
useEffect(() => {
const scrollContainer = scrollContainerRef.current
if (!scrollContainer) {
return
}
const currentScroll = scrollContainer.scrollTop
const maxScroll = scrollContainer.scrollHeight

const altScroll = currentScroll < Math.min(1, maxScroll) ? currentScroll + 1 : currentScroll - 1

scrollContainer.scrollTop = altScroll
scrollContainer.scrollTop = currentScroll
}, [scrollContainerRef])
}