Make Spotlight Dialog roving reset more stable (#7698)

This commit is contained in:
Michael Telatynski 2022-02-02 09:31:05 +00:00 committed by GitHub
parent f5226f9d5b
commit fce19d763a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,6 @@ import React, {
useCallback, useCallback,
useContext, useContext,
useEffect, useEffect,
useLayoutEffect,
useMemo, useMemo,
useState, useState,
} from "react"; } from "react";
@ -184,25 +183,15 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
}); });
}, [cli, query]); }, [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 activeSpace = SpaceStore.instance.activeSpaceRoom;
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query); const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);
const setQuery = (e: ChangeEvent<HTMLInputElement>): void => { const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
const newQuery = e.currentTarget.value; const newQuery = e.currentTarget.value;
_setQuery(newQuery); _setQuery(newQuery);
if (!query !== !newQuery) {
setImmediate(() => { setImmediate(() => {
// reset the activeRef when we start/stop querying as the view changes // reset the activeRef when we change query for best usability
const ref = rovingContext.state.refs[0]; const ref = rovingContext.state.refs[0];
if (ref) { if (ref) {
rovingContext.dispatch({ rovingContext.dispatch({
@ -214,7 +203,6 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
}); });
} }
}); });
}
}; };
const viewRoom = (roomId: string, persist = false) => { const viewRoom = (roomId: string, persist = false) => {