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

Commit fce19d7

Browse files
authored
Make Spotlight Dialog roving reset more stable (#7698)
1 parent f5226f9 commit fce19d7

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/components/views/dialogs/SpotlightDialog.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import React, {
2121
useCallback,
2222
useContext,
2323
useEffect,
24-
useLayoutEffect,
2524
useMemo,
2625
useState,
2726
} from "react";
@@ -184,37 +183,26 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
184183
});
185184
}, [cli, query]);
186185

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-
197186
const activeSpace = SpaceStore.instance.activeSpaceRoom;
198187
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);
199188

200189
const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
201190
const newQuery = e.currentTarget.value;
202191
_setQuery(newQuery);
203-
if (!query !== !newQuery) {
204-
setImmediate(() => {
205-
// reset the activeRef when we start/stop querying as the view changes
206-
const ref = rovingContext.state.refs[0];
207-
if (ref) {
208-
rovingContext.dispatch({
209-
type: Type.SetFocus,
210-
payload: { ref },
211-
});
212-
ref.current?.scrollIntoView({
213-
block: "nearest",
214-
});
215-
}
216-
});
217-
}
192+
193+
setImmediate(() => {
194+
// reset the activeRef when we change query for best usability
195+
const ref = rovingContext.state.refs[0];
196+
if (ref) {
197+
rovingContext.dispatch({
198+
type: Type.SetFocus,
199+
payload: { ref },
200+
});
201+
ref.current?.scrollIntoView({
202+
block: "nearest",
203+
});
204+
}
205+
});
218206
};
219207

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

0 commit comments

Comments
 (0)