Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7a436b85
Commit
7a436b85
authored
Dec 19, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search bar fixes
parent
6d89036a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
49 deletions
+50
-49
SearchBar.tsx
ui/snippets/searchBar/SearchBar.tsx
+48
-45
SearchBarInput.tsx
ui/snippets/searchBar/SearchBarInput.tsx
+2
-4
No files found.
ui/snippets/searchBar/SearchBar.tsx
View file @
7a436b85
import
{
Box
,
Po
pover
,
PopoverTrigger
,
PopoverContent
,
PopoverBody
,
useDisclosure
,
PopoverFooter
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Po
rtal
,
Popover
,
PopoverTrigger
,
PopoverContent
,
PopoverBody
,
useDisclosure
,
PopoverFooter
,
useOutsideClick
}
from
'
@chakra-ui/react
'
;
import
_debounce
from
'
lodash/debounce
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
type
{
FormEvent
,
FocusEvent
}
from
'
react
'
;
import
type
{
FormEvent
}
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Element
}
from
'
react-scroll
'
;
...
...
@@ -59,13 +59,15 @@ const SearchBar = ({ isHomepage }: Props) => {
inputRef
.
current
?.
querySelector
(
'
input
'
)?.
blur
();
},
[
onClose
]);
const
handle
Blur
=
React
.
useCallback
((
event
:
FocusEvent
<
HTMLFormElement
>
)
=>
{
const
isFocusIn
Menu
=
menuRef
.
current
?.
contains
(
event
.
relatedTarget
);
const
isFocusInInput
=
inputRef
.
current
?.
contains
(
event
.
relatedTarget
);
if
(
!
isFocusIn
Menu
&&
!
isFocusIn
Input
)
{
onClos
e
();
const
handle
OutsideClick
=
React
.
useCallback
((
event
:
Event
)
=>
{
const
isFocusIn
Input
=
inputRef
.
current
?.
contains
(
event
.
target
as
Node
);
if
(
!
isFocusInInput
)
{
handelHid
e
();
}
},
[
onClose
]);
},
[
handelHide
]);
useOutsideClick
({
ref
:
menuRef
,
handler
:
handleOutsideClick
});
const
handleClear
=
React
.
useCallback
(()
=>
{
handleSearchTermChange
(
''
);
...
...
@@ -118,53 +120,54 @@ const SearchBar = ({ isHomepage }: Props) => {
onChange=
{
handleSearchTermChange
}
onSubmit=
{
handleSubmit
}
onFocus=
{
handleFocus
}
onBlur=
{
handleBlur
}
onHide=
{
handelHide
}
onClear=
{
handleClear
}
isHomepage=
{
isHomepage
}
value=
{
searchTerm
}
/>
</
PopoverTrigger
>
<
PopoverContent
w=
{
`${ menuWidth.current }px`
}
ref=
{
menuRef
}
>
<
PopoverBody
p=
{
0
}
color=
"chakra-body-text"
<
Portal
>
<
PopoverContent
w=
{
`${ menuWidth.current }px`
}
ref=
{
menuRef
}
>
<
Box
maxH=
"50vh"
overflowY=
"auto"
id=
{
SCROLL_CONTAINER_ID
}
ref=
{
scrollRef
}
as=
{
Element
}
px=
{
4
}
<
PopoverBody
p=
{
0
}
color=
"chakra-body-text"
>
{
searchTerm
.
trim
().
length
===
0
&&
recentSearchKeywords
.
length
>
0
&&
(
<
SearchBarRecentKeywords
onClick=
{
handleSearchTermChange
}
onClear=
{
onClose
}
/>
)
}
{
searchTerm
.
trim
().
length
>
0
&&
(
<
SearchBarSuggest
query=
{
query
}
searchTerm=
{
debouncedSearchTerm
}
onItemClick=
{
handleItemClick
}
containerId=
{
SCROLL_CONTAINER_ID
}
/>
)
}
</
Box
>
</
PopoverBody
>
{
searchTerm
.
trim
().
length
>
0
&&
query
.
data
&&
query
.
data
.
length
>=
50
&&
(
<
PopoverFooter
>
<
LinkInternal
href=
{
route
({
pathname
:
'
/search-results
'
,
query
:
{
q
:
searchTerm
}
})
}
fontSize=
"sm"
<
Box
maxH=
"50vh"
overflowY=
"auto"
id=
{
SCROLL_CONTAINER_ID
}
ref=
{
scrollRef
}
as=
{
Element
}
px=
{
4
}
>
{
searchTerm
.
trim
().
length
===
0
&&
recentSearchKeywords
.
length
>
0
&&
(
<
SearchBarRecentKeywords
onClick=
{
handleSearchTermChange
}
onClear=
{
onClose
}
/>
)
}
{
searchTerm
.
trim
().
length
>
0
&&
(
<
SearchBarSuggest
query=
{
query
}
searchTerm=
{
debouncedSearchTerm
}
onItemClick=
{
handleItemClick
}
containerId=
{
SCROLL_CONTAINER_ID
}
/>
)
}
</
Box
>
</
PopoverBody
>
{
searchTerm
.
trim
().
length
>
0
&&
query
.
data
&&
query
.
data
.
length
>=
50
&&
(
<
PopoverFooter
>
<
LinkInternal
href=
{
route
({
pathname
:
'
/search-results
'
,
query
:
{
q
:
searchTerm
}
})
}
fontSize=
"sm"
>
View all results
</
LinkInternal
>
</
PopoverFooter
>
)
}
</
PopoverContent
>
</
LinkInternal
>
</
PopoverFooter
>
)
}
</
PopoverContent
>
</
Portal
>
</
Popover
>
);
};
...
...
ui/snippets/searchBar/SearchBarInput.tsx
View file @
7a436b85
...
...
@@ -21,7 +21,7 @@ interface Props {
const
SearchBarInput
=
({
onChange
,
onSubmit
,
isHomepage
,
onFocus
,
onBlur
,
onHide
,
onClear
,
value
}:
Props
,
ref
:
React
.
ForwardedRef
<
HTMLFormElement
>
)
=>
{
const
innerRef
=
React
.
useRef
<
HTMLFormElement
>
(
null
);
React
.
useImperativeHandle
(
ref
,
()
=>
innerRef
.
current
!
,
[]);
React
.
useImperativeHandle
(
ref
,
()
=>
innerRef
.
current
as
HTMLFormElement
,
[]);
const
[
isSticky
,
setIsSticky
]
=
React
.
useState
(
false
);
const
scrollDirection
=
useScrollDirection
();
const
isMobile
=
useIsMobile
();
...
...
@@ -56,9 +56,7 @@ const SearchBarInput = ({ onChange, onSubmit, isHomepage, onFocus, onBlur, onHid
return
()
=>
{
window
.
removeEventListener
(
'
scroll
'
,
throttledHandleScroll
);
};
// replicate componentDidMount
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
isMobile
]);
},
[
isMobile
,
handleScroll
]);
const
bgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
transformMobile
=
scrollDirection
!==
'
down
'
?
'
translateY(0)
'
:
'
translateY(-100%)
'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment