Skip to content

Commit

Permalink
fix(web): scroll dataset list to top when searching
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Oct 20, 2023
1 parent c3a4e7e commit dc2b007
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { get, isNil, sortBy } from 'lodash'
import { lighten } from 'polished'
import React, { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react'
import { ListGroup } from 'reactstrap'
import { useRecoilState, useRecoilValue } from 'recoil'
import { ListGenericCss } from 'src/components/Common/List'
import { DatasetInfo } from 'src/components/Main/DatasetInfo'
Expand Down Expand Up @@ -95,6 +94,9 @@ export function DatasetSelectorList({
}
}, [autodetectRunState, autodetectResult.itemsInclude, onDatasetHighlighted, setAutodetectRunState])

const ulRef = useRef<HTMLUListElement>(null)
useEffect(() => ulRef.current?.scrollTo({ top: 0, left: 0, behavior: 'smooth' }), [searchTerm])

const listItems = useMemo(() => {
return (
<>
Expand Down Expand Up @@ -126,7 +128,7 @@ export function DatasetSelectorList({
)
}, [datasetHighlighted, itemsInclude, itemsNotInclude, itemsStartWith, onItemClick])

return <Ul>{listItems}</Ul>
return <Ul ref={ulRef}>{listItems}</Ul>
}

function nodeRefSetOrDelete<T extends HTMLElement>(map: Map<string, T>, key: string) {
Expand All @@ -139,7 +141,7 @@ function nodeRefSetOrDelete<T extends HTMLElement>(map: Map<string, T>, key: str
}
}

export const Ul = styled(ListGroup)`
export const Ul = styled.ul`
${ListGenericCss};
flex: 1;
overflow: auto;
Expand Down

0 comments on commit dc2b007

Please sign in to comment.