Skip to content

Commit 47ce6ec

Browse files
VanAndersonsmockle
andauthored
implement Scroll flash into SelectPanel (#1276)
* implement scrollflash into SelectPanel * Update src/hooks/useScrollFlash.ts Co-authored-by: Clay Miller <[email protected]> * revise useScrollFlash * don't dispatch scrollFlash event Co-authored-by: Clay Miller <[email protected]>
1 parent e8347e4 commit 47ce6ec

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/FilteredActionList/FilteredActionList.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {itemActiveDescendantClass} from '../ActionList/Item'
1111
import {useProvidedStateOrCreate} from '../hooks/useProvidedStateOrCreate'
1212
import styled from 'styled-components'
1313
import {get} from '../constants'
14+
import useScrollFlash from '../hooks/useScrollFlash'
1415

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

125+
useScrollFlash(scrollContainerRef)
126+
124127
return (
125128
<Flex ref={containerRef} flexDirection="column" overflow="hidden">
126129
<StyledHeader>

src/hooks/useScrollFlash.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, {useEffect} from 'react'
2+
/**
3+
* This hook will flash the scrollbars for a ref of a container that has scrollable overflow
4+
* @param scrollContainerRef The ref of the scrollable content
5+
*/
6+
export default function useScrollFlash(scrollContainerRef: React.RefObject<HTMLElement>) {
7+
// https://adxlv.computer/projects/flash-scrollers/
8+
useEffect(() => {
9+
const scrollContainer = scrollContainerRef.current
10+
if (!scrollContainer) {
11+
return
12+
}
13+
const currentScroll = scrollContainer.scrollTop
14+
const maxScroll = scrollContainer.scrollHeight
15+
16+
const altScroll = currentScroll < Math.min(1, maxScroll) ? currentScroll + 1 : currentScroll - 1
17+
18+
scrollContainer.scrollTop = altScroll
19+
scrollContainer.scrollTop = currentScroll
20+
}, [scrollContainerRef])
21+
}

0 commit comments

Comments
 (0)