added ref to remove focus after input clear
This commit is contained in:
parent
11f5baa782
commit
0578358e53
|
@ -57,7 +57,7 @@ interface Props {
|
||||||
export default function SearchBar(props: Props) {
|
export default function SearchBar(props: Props) {
|
||||||
const [allFiles, setAllFiles] = useState<File[]>([]);
|
const [allFiles, setAllFiles] = useState<File[]>([]);
|
||||||
const [allCollections, setAllCollections] = useState<Collection[]>([]);
|
const [allCollections, setAllCollections] = useState<Collection[]>([]);
|
||||||
|
const selectRef = useRef(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!props.isOpen && allFiles?.length > 0) {
|
if (!props.isOpen && allFiles?.length > 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -69,6 +69,9 @@ export default function SearchBar(props: Props) {
|
||||||
main();
|
main();
|
||||||
}, [props.isOpen]);
|
}, [props.isOpen]);
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
// Functionality
|
||||||
|
//==========================
|
||||||
const getAutoCompleteSuggestion = async (searchPhrase: string) => {
|
const getAutoCompleteSuggestion = async (searchPhrase: string) => {
|
||||||
let option = new Array<Suggestion>();
|
let option = new Array<Suggestion>();
|
||||||
if (!searchPhrase?.length) {
|
if (!searchPhrase?.length) {
|
||||||
|
@ -132,8 +135,13 @@ export default function SearchBar(props: Props) {
|
||||||
props.setOpen(false);
|
props.setOpen(false);
|
||||||
props.setFiles(allFiles);
|
props.setFiles(allFiles);
|
||||||
props.setCollections(allCollections);
|
props.setCollections(allCollections);
|
||||||
|
setTimeout(() => selectRef.current?.blur(), 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
// UI
|
||||||
|
//==========================
|
||||||
|
|
||||||
const getIconByType = (type: SuggestionType) =>
|
const getIconByType = (type: SuggestionType) =>
|
||||||
type === SuggestionType.DATE ? <DateIcon /> : <LocationIcon />;
|
type === SuggestionType.DATE ? <DateIcon /> : <LocationIcon />;
|
||||||
|
|
||||||
|
@ -225,6 +233,7 @@ export default function SearchBar(props: Props) {
|
||||||
SingleValue: SingleValueWithIcon,
|
SingleValue: SingleValueWithIcon,
|
||||||
Control: ControlWithIcon,
|
Control: ControlWithIcon,
|
||||||
}}
|
}}
|
||||||
|
ref={selectRef}
|
||||||
placeholder={constants.SEARCH_HINT}
|
placeholder={constants.SEARCH_HINT}
|
||||||
loadOptions={getOptions}
|
loadOptions={getOptions}
|
||||||
onChange={filterFiles}
|
onChange={filterFiles}
|
||||||
|
|
Loading…
Reference in a new issue