Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5144637

Browse files
authored
Tweak spotlight roving behaviour to reset when changing query (#7656)
1 parent b77d31b commit 5144637

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/views/dialogs/SpotlightDialog.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import React, {
2121
useCallback,
2222
useContext,
2323
useEffect,
24+
useLayoutEffect,
2425
useMemo,
2526
useState,
2627
} from "react";
@@ -183,6 +184,16 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
183184
});
184185
}, [cli, query]);
185186

187+
// Reset the selection back to the first item whenever the query changes
188+
useLayoutEffect(() => {
189+
rovingContext.dispatch({
190+
type: Type.SetFocus,
191+
payload: {
192+
ref: rovingContext.state.refs[0],
193+
},
194+
});
195+
}, [query]); // eslint-disable-line react-hooks/exhaustive-deps
196+
186197
const activeSpace = SpaceStore.instance.activeSpaceRoom;
187198
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);
188199

0 commit comments

Comments
 (0)