From d9d4ffab4c407d8576e55f445a8dfc8b3908c2f8 Mon Sep 17 00:00:00 2001 From: "pouriade.com" Date: Tue, 27 Oct 2026 23:06:16 -0700 Subject: [PATCH] Close the chat search back to its button in one place Escape and the results' Clear share closeSearchToButton, and the rows take syncIndex directly rather than through an alias. --- .../features/chat-list/components/ChatList.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/web/src/features/chat-list/components/ChatList.tsx b/apps/web/src/features/chat-list/components/ChatList.tsx index 6c0139a..bfd84ee 100644 --- a/apps/web/src/features/chat-list/components/ChatList.tsx +++ b/apps/web/src/features/chat-list/components/ChatList.tsx @@ -97,7 +97,6 @@ export function ChatList() { // is asked of the router when one is deleted, a call React Compiler keeps on the router, which // stays the same, so opening another chat leaves the callback, and the rows, alone. const router = useRouter() - const changed = syncIndex const deleted = (skey: string) => { if (router.matchRoute({ to: '/chat/$skey', params: { skey } })) void navigate({ to: '/' }) } @@ -107,6 +106,11 @@ export function ChatList() { setQuery('') setSearchOpen(false) } + /** Close the search from inside it, with the focus back on the button that opened it. */ + const closeSearchToButton = () => { + closeSearch() + searchButton.current?.focus() + } const signOut = useSignOut() // The function alone, which stays the same, rather than the mutation, which changes as it runs. @@ -157,9 +161,7 @@ export function ChatList() { value={query} onChange={(e) => setQuery(e.target.value)} onKeyDown={(e) => { - if (e.key !== 'Escape') return - closeSearch() - searchButton.current?.focus() + if (e.key === 'Escape') closeSearchToButton() }} className="h-row min-w-0 flex-1 rounded-sm bg-row-hover ps-[calc(var(--spacing-row-inset)+--spacing(5.75))] pe-row-inset outline-none hover:bg-row-active focus-visible:bg-row-active" /> @@ -173,10 +175,7 @@ export function ChatList() { results={found.results} remaining={found.remaining} loading={found.isLoading} - onClear={() => { - closeSearch() - searchButton.current?.focus() - }} + onClear={closeSearchToButton} /> )} @@ -193,7 +192,7 @@ export function ChatList() { conversations={conversations} seen={seen} current={current} - onChanged={changed} + onChanged={syncIndex} onDeleted={deleted} /> {/* Where the loaded chats end, which loads the next page as it nears view, so no -- knotmirror 0.0.1