Make Spotlight Dialog roving reset more stable (#7698)
This commit is contained in:
parent
f5226f9d5b
commit
fce19d763a
1 changed files with 14 additions and 26 deletions
|
@ -21,7 +21,6 @@ import React, {
|
|||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
|
@ -184,25 +183,15 @@ 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
|
||||
// reset the activeRef when we change query for best usability
|
||||
const ref = rovingContext.state.refs[0];
|
||||
if (ref) {
|
||||
rovingContext.dispatch({
|
||||
|
@ -214,7 +203,6 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
|
|||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const viewRoom = (roomId: string, persist = false) => {
|
||||
|
|
Loading…
Reference in a new issue