-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change selection type to
string[]
and adjust usages (init…
…ial)
- Loading branch information
1 parent
4858365
commit 7e20c88
Showing
13 changed files
with
80 additions
and
58 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ export const useScrollListScrollToSelected = <T, EL extends HTMLElement>({ | |
scrollListRef: RefObject<EL>; | ||
items: ListProps<T>['items']; | ||
getId: ListProps<T>['getId']; | ||
selected: string | undefined; | ||
selected: string[]; | ||
averageItemSize: number; | ||
itemsDimensions: MutableRefObject<DimensionsById>; | ||
mountedItems: MutableRefObject<Set<string>>; | ||
|
@@ -34,7 +34,7 @@ export const useScrollListScrollToSelected = <T, EL extends HTMLElement>({ | |
const loadingTimeout = useRef(0); | ||
const timeout = useRef(0); | ||
const isScrollingToSelection = useRef(false); | ||
const selectedIndex = useMemo(() => items.findIndex((i) => getId(i) === selected), [items, getId, selected]); | ||
const selectedIndex = useMemo(() => items.findIndex((i) => getId(i) === selected[0]), [items, getId, selected]); | ||
const calculateDistance = useCallback( | ||
({ itemIndex, direction }: { itemIndex: number; direction: 'up' | 'down' }) => { | ||
let distance = 0; | ||
|
@@ -59,7 +59,16 @@ export const useScrollListScrollToSelected = <T, EL extends HTMLElement>({ | |
|
||
return Math.floor((direction === 'down' ? 1 : -1) * distance); | ||
}, | ||
[averageItemSize, extraRenderSize, getId, isHorizontal, items, itemsDimensions, scrollWindowSize, selectedIndex] | ||
[ | ||
averageItemSize, | ||
extraRenderSize, | ||
getId, | ||
isHorizontal, | ||
items, | ||
itemsDimensions, | ||
scrollWindowSize, | ||
selectedIndex, | ||
], | ||
); | ||
const cleanUp = () => { | ||
isScrollingToSelection.current = false; | ||
|
@@ -78,7 +87,7 @@ export const useScrollListScrollToSelected = <T, EL extends HTMLElement>({ | |
const node = scrollListRef.current?.querySelector(`[data-id='${getId(items[selected]!)}']`); | ||
if (!node) { | ||
timeout.current = window.setTimeout( | ||
() => isScrollingToSelection.current && scrollTo(selected, true) | ||
() => isScrollingToSelection.current && scrollTo(selected, true), | ||
This comment has been minimized.
Sorry, something went wrong.
alissawix
Contributor
|
||
); | ||
} else { | ||
scrollIntoViewIfNeeded(node, { | ||
|
@@ -108,7 +117,7 @@ export const useScrollListScrollToSelected = <T, EL extends HTMLElement>({ | |
|
||
timeout.current = window.setTimeout(() => scrollIntoView(selectedIndex, repeated ? 'center' : position)); | ||
}, | ||
[scrollListRef, scrollWindow, mountedItems, items, getId, calculateDistance] | ||
[scrollListRef, scrollWindow, mountedItems, items, getId, calculateDistance], | ||
); | ||
|
||
useEffect(() => { | ||
|
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
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
Oops, something went wrong.
without reading the autocomplete code, that is a bit risky...
the easy way out, if it uses the list is to assume that the array is of length 0 | 1 at this point