mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Scroll to top when selecting current page in search (#4578)
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"gitbook": patch
|
||||
---
|
||||
|
||||
Scroll to the top when selecting a search result for the page already being viewed.
|
||||
@@ -198,14 +198,23 @@ export const SearchResults = React.forwardRef(function SearchResults(
|
||||
const itemKey = getResultKey(item);
|
||||
const shouldAnimateItem =
|
||||
shouldAnimateResults || !seenResultKeys.current.has(itemKey);
|
||||
const handleResultSelect = () => {
|
||||
const handleResultSelect = (
|
||||
event: React.MouseEvent<HTMLAnchorElement>
|
||||
) => {
|
||||
const isPageResult =
|
||||
item.type === 'local-page' ||
|
||||
item.type === 'page' ||
|
||||
item.type === 'record';
|
||||
|
||||
if (
|
||||
query &&
|
||||
siteSpaceId &&
|
||||
(item.type === 'local-page' ||
|
||||
item.type === 'page' ||
|
||||
item.type === 'record')
|
||||
isPageResult &&
|
||||
!event.currentTarget.hash &&
|
||||
event.currentTarget.pathname === window.location.pathname
|
||||
) {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
if (query && siteSpaceId && isPageResult) {
|
||||
addRecentSearchQuery(siteSpaceId, query, 'search');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user