Skip to content

Commit

Permalink
Make Spotlight Dialog roving reset more stable (#7698)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Feb 2, 2022
1 parent f5226f9 commit fce19d7
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/components/views/dialogs/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import React, {
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useState,
} from "react";
Expand Down Expand Up @@ -184,37 +183,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

0 comments on commit fce19d7

Please sign in to comment.