From fce19d763a4dba73f71f8d5a344922f975ee292f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 2 Feb 2022 09:31:05 +0000 Subject: [PATCH] Make Spotlight Dialog roving reset more stable (#7698) --- .../views/dialogs/SpotlightDialog.tsx | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/components/views/dialogs/SpotlightDialog.tsx b/src/components/views/dialogs/SpotlightDialog.tsx index 8faac39406..2d3154cc83 100644 --- a/src/components/views/dialogs/SpotlightDialog.tsx +++ b/src/components/views/dialogs/SpotlightDialog.tsx @@ -21,7 +21,6 @@ import React, { useCallback, useContext, useEffect, - useLayoutEffect, useMemo, useState, } from "react"; @@ -184,37 +183,26 @@ const SpotlightDialog: React.FC = ({ 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): 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) => {