From a409611ea40a79fdeedfaed0ddc844b1bd2c1b96 Mon Sep 17 00:00:00 2001 From: OlegMoshkovich Date: Sat, 7 Oct 2023 18:50:57 +0200 Subject: [PATCH] replace the search bar with auto complete --- src/Components/SearchBar.jsx | 61 ++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/Components/SearchBar.jsx b/src/Components/SearchBar.jsx index b3d5ad70a..31d619911 100644 --- a/src/Components/SearchBar.jsx +++ b/src/Components/SearchBar.jsx @@ -1,6 +1,7 @@ import React, {useRef, useEffect, useState} from 'react' import {useLocation, useNavigate, useSearchParams} from 'react-router-dom' import InputAdornment from '@mui/material/InputAdornment' +import Autocomplete from '@mui/material/Autocomplete' import IconButton from '@mui/material/IconButton' import TextField from '@mui/material/TextField' import {looksLikeLink, githubUrlOrPathToSharePath} from '../ShareRoutes' @@ -23,7 +24,6 @@ export default function SearchBar({fileOpen}) { const [searchParams, setSearchParams] = useSearchParams() const [inputText, setInputText] = useState('') const [error, setError] = useState('') - const onInputChange = (event) => setInputText(event.target.value) const searchInputRef = useRef(null) @@ -83,42 +83,49 @@ export default function SearchBar({fileOpen}) { // to have them share the same width, which is now set in the parent // container (CadView). return ( -
- + - - - ), - endAdornment: inputText.length > 0 ? ( - + onChange={(_, newValue) => setInputText(newValue || '')} + onInputChange={(_, newInputValue) => setInputText(newInputValue || '')} + inputValue={inputText} + renderInput={(params) => ( + + + + ), + endAdornment: inputText.length > 0 ? ( + { setInputText('') setError('') navWithSearchParamRemoved(navigate, location.pathname, QUERY_PARAM) }} - style={{padding: 0, opacity: .5}} + style={{padding: 0, opacity: 0.5}} > - + - ) : null, - }} + ) : null, + }} + /> + )} /> )