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

Make Spotlight Dialog roving reset more stable #7698

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions src/components/views/dialogs/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,37 +184,26 @@ 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);

const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
const newQuery = e.currentTarget.value;
_setQuery(newQuery);
if (!query !== !newQuery) {
setImmediate(() => {
// reset the activeRef when we start/stop querying as the view changes
const ref = rovingContext.state.refs[0];
if (ref) {
rovingContext.dispatch({
type: Type.SetFocus,
payload: { ref },
});
ref.current?.scrollIntoView({
block: "nearest",
});
}
});
}

setImmediate(() => {
// reset the activeRef when we change query for best usability
const ref = rovingContext.state.refs[0];
if (ref) {
rovingContext.dispatch({
type: Type.SetFocus,
payload: { ref },
});
ref.current?.scrollIntoView({
block: "nearest",
});
}
});
};

const viewRoom = (roomId: string, persist = false) => {
Expand Down