diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index f196906..26f556d 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { FormEvent, useState } from "react"; import { FaSearch } from "react-icons/fa"; import { findProf } from "../util/data"; import "../index.css"; @@ -26,37 +26,46 @@ const SearchBar: React.FC = ({ onSelectProfessor }) => { setdropdownVisibility(false); }; + const onSubmitForm = (e: FormEvent) => { + // Select the top option in the list if enter is pressed + e.preventDefault(); + + if (displayedProfs.length > 0) { + setSearchName(displayedProfs[0].prof.name); + onSelectProfessor(displayedProfs[0]); + setdropdownVisibility(false); + } + } + return ( - <> -
-
-
- - handleChange(e.target.value)} - /> -
+
+
+
+ + handleChange(e.target.value)} + />
- {dropdownVisibility && ( -
- {displayedProfs.map((timetable) => ( -
onSelect(timetable)} - className="dropdown-row" - key={timetable.prof.profile_url} - > - {timetable.prof.name} | {timetable.prof.dept_code} -
- ))} -
- )}
- + {dropdownVisibility && ( +
+ {displayedProfs.map((timetable) => ( +
onSelect(timetable)} + className="dropdown-row" + key={timetable.prof.profile_url} + > + {timetable.prof.name} | {timetable.prof.dept_code} +
+ ))} +
+ )} +
); };