Tweak spotlight roving behaviour to reset when changing query (#7656)

pull/21833/head
Michael Telatynski 2022-01-27 16:40:22 +00:00 committed by GitHub
parent b77d31bb4f
commit 51446378e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import React, {
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useState,
} from "react";
@ -183,6 +184,16 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
});
}, [cli, query]);
// Reset the selection back to the first item whenever the query changes
useLayoutEffect(() => {
rovingContext.dispatch({
type: Type.SetFocus,
payload: {
ref: rovingContext.state.refs[0],
},
});
}, [query]); // eslint-disable-line react-hooks/exhaustive-deps
const activeSpace = SpaceStore.instance.activeSpaceRoom;
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);