Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(theme): fix highlight effect when operating with keyboard (#1364) #1366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
const pageSearcherConfigRef = useRef<PageSearcherConfig | null>(null);
const searchResultRef = useRef(null);
const searchResultTabRef = useRef(null);
const mousePositionRef = useRef<{
pageX: number | null;
pageY: number | null;
}>({
pageX: null,
pageY: null,
});

// only scroll after keydown arrow up and arrow down.
const [canScroll, setCanScroll] = useState(false);
Expand Down Expand Up @@ -394,10 +401,23 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
key={`${suggestion.title}-${suggestionIndex}`}
suggestion={suggestion}
isCurrent={suggestionIndex === currentSuggestionIndex}
setCurrentSuggestionIndex={() => {
setCurrentSuggestionIndex={event => {
if (
mousePositionRef.current.pageX === event.pageX &&
mousePositionRef.current.pageY === event.pageY
) {
return;
}

setCanScroll(false);
setCurrentSuggestionIndex(suggestionIndex);
}}
onMouseMove={event => {
mousePositionRef.current = {
pageX: event.pageX,
pageY: event.pageY,
};
}}
closeSearch={() => {
clearSearchState();
}}
Expand Down
7 changes: 6 additions & 1 deletion packages/theme-default/src/components/Search/SuggestItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ export function SuggestItem({
setCurrentSuggestionIndex,
inCurrentDocIndex,
scrollTo,
onMouseMove,
}: {
suggestion: DefaultMatchResultItem;
closeSearch: () => void;
isCurrent: boolean;
setCurrentSuggestionIndex: () => void;
setCurrentSuggestionIndex: (
event: React.MouseEvent<HTMLLIElement, MouseEvent>,
) => void;
onMouseMove: (event: React.MouseEvent<HTMLLIElement, MouseEvent>) => void;
inCurrentDocIndex: boolean;
scrollTo: (top: number, height: number) => void;
}) {
Expand Down Expand Up @@ -118,6 +122,7 @@ export function SuggestItem({
key={suggestion.link}
className={`${styles.suggestItem} ${isCurrent ? styles.current : ''}`}
onMouseEnter={setCurrentSuggestionIndex}
onMouseMove={onMouseMove}
ref={selfRef}
>
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
}
}

&:hover,
&.current {
> a {
background-color: var(--rp-c-brand);
Expand Down