fix(web): reset goto anything search after dialog closes (#41976)

This commit is contained in:
yyh 2026-09-08 09:38:11 +00:00 committed by GitHub
parent c9e0118ae9
commit 0955b8b810
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 17 deletions

View File

@ -388,7 +388,7 @@ describe('GotoAnything', () => {
expect(input).toHaveFocus()
})
it('should reset search query when modal opens', async () => {
it('should reopen with an empty search after the modal finishes closing', async () => {
const user = userEvent.setup()
renderGotoAnything(<GotoAnything />)

View File

@ -226,7 +226,7 @@ function chunkArray<T>(items: readonly T[], size: number): T[][] {
return rows
}
function GotoAnythingDialog() {
export function GotoAnything() {
const { t } = useTranslation()
const pathname = usePathname()
const router = useRouter()
@ -379,8 +379,8 @@ function GotoAnythingDialog() {
const dedupedResults = dedupeSearchResults(searchResults)
const groupedResults = groupSearchResults(dedupedResults)
function resetSearch() {
setSearchQuery('')
function handleDialogOpenChangeComplete(open: boolean) {
if (!open) setSearchQuery('')
}
useHotkey(
@ -432,13 +432,6 @@ function GotoAnythingDialog() {
}
}
function handleAutocompleteOpenChange(
nextOpen: boolean,
eventDetails: AutocompleteChangeEventDetails,
) {
if (!nextOpen && eventDetails.reason === 'escape-key') gotoAnythingDialogHandle.close()
}
function handleAutocompleteValueChange(
nextValue: string,
eventDetails: AutocompleteChangeEventDetails,
@ -500,7 +493,10 @@ function GotoAnythingDialog() {
return (
<>
<SlashCommandProvider />
<Dialog handle={gotoAnythingDialogHandle} onOpenChange={resetSearch}>
<Dialog
handle={gotoAnythingDialogHandle}
onOpenChangeComplete={handleDialogOpenChangeComplete}
>
<DialogPortal>
<DialogBackdrop />
<DialogPopup
@ -522,7 +518,6 @@ function GotoAnythingDialog() {
items={visibleOptions}
value={searchQuery}
onValueChange={handleAutocompleteValueChange}
onOpenChange={handleAutocompleteOpenChange}
itemToStringValue={optionToInputValue}
filter={null}
grid={isCommandsMode}
@ -709,7 +704,3 @@ function GotoAnythingDialog() {
</>
)
}
export function GotoAnything() {
return <GotoAnythingDialog />
}