diff --git a/web/src/main/javascript/src/components/Header/Header.tsx b/web/src/main/javascript/src/components/Header/Header.tsx index 526057f..ab38123 100644 --- a/web/src/main/javascript/src/components/Header/Header.tsx +++ b/web/src/main/javascript/src/components/Header/Header.tsx @@ -111,10 +111,11 @@ export default function Header({ flexShrink: 0, alignItems: "center", visibility: searchSectionHidden ? "hidden" : "unset", + pointerEvents: searchSectionHidden ? 'none' : 'unset' }} > - +
, Control, }} styles={{ @@ -262,26 +259,31 @@ export default function SearchBar({
); + interface IClearIndicatorProps extends ClearIndicatorProps< + OncoTreeSearchOption, + false, + GroupBase +> { + searchResults: D3OncoTreeNode[] | undefined, + searchResultsIndex: number | undefined + } + function ClearIndicator( - props: ClearIndicatorProps< - OncoTreeSearchOption, - false, - GroupBase - >, + {searchResults, searchResultsIndex, ...props}: IClearIndicatorProps, ) { const inputStyle = props.getStyles("input", { ...props, isHidden: false }); const inputColor = inputStyle.color ?? "black"; const clearIndicatorClass = css(props.getStyles("clearIndicator", props)); const resultsAndIndexDefined = - cancerTypeResults !== undefined && cancerTypeResultsIndex !== undefined; + searchResults !== undefined && searchResultsIndex !== undefined; function getResultsNumberSpan() { if (!resultsAndIndexDefined) { return undefined; } - if (cancerTypeResults.length === 0) { + if (searchResults.length === 0) { return ( {`${cancerTypeResultsIndex + 1}/${cancerTypeResults.length}`} + >{`${searchResultsIndex + 1}/${searchResults.length}`} ); } - const getPreviousResult = resultsAndIndexDefined - ? () => { - let newIndex = cancerTypeResults.length - 1; + const getPreviousResult = useCallback(() => { + if (!resultsAndIndexDefined) { + return; + } + + let newIndex = searchResults.length - 1; if (cancerTypeResultsIndex !== 0) { - newIndex = cancerTypeResultsIndex - 1; + newIndex = searchResultsIndex - 1; } - oncoTree?.focus(cancerTypeResults[newIndex]); + oncoTree?.focus(searchResults[newIndex]); setCancerTypeResultsIndex(newIndex); + }, [resultsAndIndexDefined, searchResults, searchResultsIndex]); + + const getNextResult = useCallback(() => { + if (!resultsAndIndexDefined) { + return; } - : undefined; - const getNextResult = resultsAndIndexDefined - ? () => { - let newIndex = 0; + let newIndex = 0; if ( cancerTypeResultsIndex !== - cancerTypeResults.length - 1 + searchResults.length - 1 ) { - newIndex = cancerTypeResultsIndex + 1; + newIndex = searchResultsIndex + 1; } - oncoTree?.focus(cancerTypeResults[newIndex]); + oncoTree?.focus(searchResults[newIndex]); setCancerTypeResultsIndex(newIndex); - } - : undefined + }, [resultsAndIndexDefined, searchResults, searchResultsIndex]); + + const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0; return ( <> {getResultsNumberSpan()} - {resultsAndIndexDefined && cancerTypeResults.length > 0 && ( + {resultsAndIndexDefined && searchResults.length > 0 && (