Skip to content

Commit

Permalink
fix: search modal stays open with metaKey (#8090)
Browse files Browse the repository at this point in the history
  • Loading branch information
EoinFalconer authored Dec 17, 2024
1 parent 3d5f1d3 commit f95a3d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Card, Flex} from '@sanity/ui'
import {useCallback} from 'react'
import {type MouseEvent, useCallback} from 'react'
import {styled} from 'styled-components'

import {CommandList, type CommandListRenderItemCallback} from '../../../../../../components'
Expand Down Expand Up @@ -49,12 +49,18 @@ export function SearchResults({disableIntentLink, inputElement, onItemSelect}: S
/**
* Add current search to recent searches, trigger child item click and close search
*/
const handleSearchResultClick = useCallback(() => {
if (recentSearchesStore) {
recentSearchesStore.addSearch(terms, filters)
}
onClose?.()
}, [filters, onClose, recentSearchesStore, terms])
const handleSearchResultClick = useCallback(
(e: MouseEvent<HTMLElement>) => {
if (recentSearchesStore) {
recentSearchesStore.addSearch(terms, filters)
}
// We don't want to close the search if they are opening their result in a new tab
if (!e.metaKey && !e.ctrlKey) {
onClose?.()
}
},
[filters, onClose, recentSearchesStore, terms],
)

const handleEndReached = useCallback(() => {
dispatch({type: 'PAGE_INCREMENT'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface SearchResultItemProps extends ResponsiveMarginProps, ResponsivePadding
documentId: string
documentType: string
layout?: GeneralPreviewLayoutKey
onClick?: () => void
onClick?: (e: MouseEvent<HTMLElement>) => void
onItemSelect?: ItemSelectHandler
}

Expand Down Expand Up @@ -44,7 +44,7 @@ export function SearchResultItem({
if (!disableIntentLink) {
onIntentClick(e)
}
onClick?.()
onClick?.(e)
},
[onItemSelect, documentId, documentType, disableIntentLink, onClick, onIntentClick],
)
Expand Down

0 comments on commit f95a3d1

Please sign in to comment.