SearchInput+IconGrid: scroll to top of grid on search change
When the debounced search query changes, scroll to the top of the grid if the query is not the empty string. This has the same smooth behavior as the scroll buttons, which is not currently available on WebKit.
This commit is contained in:
@@ -155,3 +155,8 @@
|
|||||||
padding: 0 16px 4px;
|
padding: 0 16px 4px;
|
||||||
min-height: 80vh;
|
min-height: 80vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.beacon {
|
||||||
|
position: relative;
|
||||||
|
top: -64px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const IconGrid: React.FC<IconGridProps> = () => {
|
|||||||
className="grid-container"
|
className="grid-container"
|
||||||
style={{ backgroundColor: isDark ? "#35313D" : "" }}
|
style={{ backgroundColor: isDark ? "#35313D" : "" }}
|
||||||
>
|
>
|
||||||
|
<i id="beacon" className="beacon" />
|
||||||
<motion.div
|
<motion.div
|
||||||
className="grid"
|
className="grid"
|
||||||
initial="hidden"
|
initial="hidden"
|
||||||
|
|||||||
@@ -13,7 +13,17 @@ const SearchInput: React.FC<SearchInputProps> = () => {
|
|||||||
const [query, setQuery] = useRecoilState(searchQueryAtom);
|
const [query, setQuery] = useRecoilState(searchQueryAtom);
|
||||||
void query;
|
void query;
|
||||||
|
|
||||||
const [isReady] = useDebounce(() => setQuery(value), 250, [value]);
|
const [isReady] = useDebounce(
|
||||||
|
() => {
|
||||||
|
setQuery(value);
|
||||||
|
value &&
|
||||||
|
void document
|
||||||
|
.getElementById("beacon")
|
||||||
|
?.scrollIntoView({ block: "start", behavior: "smooth" });
|
||||||
|
},
|
||||||
|
250,
|
||||||
|
[value]
|
||||||
|
);
|
||||||
|
|
||||||
const handleCancelSearch = () => {
|
const handleCancelSearch = () => {
|
||||||
setValue("");
|
setValue("");
|
||||||
|
|||||||
Reference in New Issue
Block a user