|
@@ -3,7 +3,7 @@ import React, {
|
|
|
useState, useCallback, useEffect,
|
|
useState, useCallback, useEffect,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
-import Downshift from 'downshift';
|
|
|
|
|
|
|
+import Downshift, { type DownshiftState, type StateChangeOptions } from 'downshift';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
import { Modal, ModalBody } from 'reactstrap';
|
|
import { Modal, ModalBody } from 'reactstrap';
|
|
|
|
|
|
|
@@ -36,6 +36,18 @@ const SearchModal = (): JSX.Element => {
|
|
|
closeSearchModal();
|
|
closeSearchModal();
|
|
|
}, [closeSearchModal, router, searchKeyword]);
|
|
}, [closeSearchModal, router, searchKeyword]);
|
|
|
|
|
|
|
|
|
|
+ const stateReducer = (state: DownshiftState<DownshiftItem>, changes: StateChangeOptions<DownshiftItem>) => {
|
|
|
|
|
+ // Do not update highlightedIndex on mouse hover
|
|
|
|
|
+ if (changes.type === Downshift.stateChangeTypes.itemMouseEnter) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...changes,
|
|
|
|
|
+ highlightedIndex: state.highlightedIndex,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return changes;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (!searchModalData?.isOpened) {
|
|
if (!searchModalData?.isOpened) {
|
|
|
setSearchKeyword('');
|
|
setSearchKeyword('');
|
|
@@ -47,6 +59,7 @@ const SearchModal = (): JSX.Element => {
|
|
|
<ModalBody>
|
|
<ModalBody>
|
|
|
<Downshift
|
|
<Downshift
|
|
|
onSelect={selectSearchMenuItemHandler}
|
|
onSelect={selectSearchMenuItemHandler}
|
|
|
|
|
+ stateReducer={stateReducer}
|
|
|
defaultIsOpen
|
|
defaultIsOpen
|
|
|
>
|
|
>
|
|
|
{({
|
|
{({
|
|
@@ -55,7 +68,6 @@ const SearchModal = (): JSX.Element => {
|
|
|
getItemProps,
|
|
getItemProps,
|
|
|
getMenuProps,
|
|
getMenuProps,
|
|
|
highlightedIndex,
|
|
highlightedIndex,
|
|
|
- setHighlightedIndex,
|
|
|
|
|
}) => (
|
|
}) => (
|
|
|
<div {...getRootProps({}, { suppressRefError: true })}>
|
|
<div {...getRootProps({}, { suppressRefError: true })}>
|
|
|
<div className="text-muted d-flex justify-content-center align-items-center p-1">
|
|
<div className="text-muted d-flex justify-content-center align-items-center p-1">
|
|
@@ -75,8 +87,7 @@ const SearchModal = (): JSX.Element => {
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- {/* see: https://github.com/downshift-js/downshift/issues/582#issuecomment-423592531 */}
|
|
|
|
|
- <ul {...getMenuProps({ onMouseLeave: () => { setHighlightedIndex(-1) } })} className="list-unstyled">
|
|
|
|
|
|
|
+ <ul {...getMenuProps()} className="list-unstyled">
|
|
|
<div className="border-top mt-3 mb-2" />
|
|
<div className="border-top mt-3 mb-2" />
|
|
|
<SearchMethodMenuItem
|
|
<SearchMethodMenuItem
|
|
|
activeIndex={highlightedIndex}
|
|
activeIndex={highlightedIndex}
|