Skip to content

Commit

Permalink
fix: input search fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Oct 24, 2023
1 parent ee18f82 commit 4e354d7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/forms/filters/InputSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function InputSearch({
onResultClick,
}: BookSearchResultsType) {
const containerRef = useRef(null);
const inputRef = useRef<HTMLDivElement>(null);
const colorIcons = useColorModeValue('gray.700', 'gray.300');
const bgInput = useColorModeValue('white', 'black');
const colorInput = useColorModeValue('gray.900', 'gray.100');
Expand All @@ -62,8 +63,13 @@ export function InputSearch({

useOutsideClick({
ref: containerRef,
handler: () => {
if (search.query) {
handler: (event) => {
// Verificar si el clic ocurrió fuera del inputRef
if (
inputRef.current &&
!inputRef.current.contains(event.target as Node) &&
search.query
) {
setSearch({ ...search, query: '' });
}
},
Expand Down Expand Up @@ -121,7 +127,7 @@ export function InputSearch({

return (
<>
<FormControl w={width} mr={{ base: 0, lg: 2 }} ref={containerRef}>
<FormControl w={width} mr={{ base: 0, lg: 2 }} ref={inputRef}>
<InputGroup>
<InputLeftElement>
<Icon as={FiSearch} boxSize='20px' color={colorIcons} />
Expand Down Expand Up @@ -166,6 +172,7 @@ export function InputSearch({
</InputGroup>
</FormControl>
<Container
ref={containerRef}
display={search.query.length >= 3 ? 'block' : 'none'}
w={width}
maxH='300px'
Expand Down

1 comment on commit 4e354d7

@vercel
Copy link

@vercel vercel bot commented on 4e354d7 Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-git-main-franqsanz.vercel.app
xbu.vercel.app
xbu-franqsanz.vercel.app

Please sign in to comment.