All files / components/RosterStudent RosterStudentDropdown.jsx

100% Statements 27/27
100% Branches 5/5
100% Functions 2/2
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x 1x 1x   1x 23x 23x 23x 23x 23x 108x 108x 108x   23x 23x 23x 23x 23x 23x 23x 23x 6x 5x 6x 1x 1x 6x     23x  
import React from "react";
import { Typeahead } from "react-bootstrap-typeahead";
import "react-bootstrap-typeahead/css/Typeahead.css";
 
export default function RosterStudentDropdown({
  rosterStudents,
  setValue,
  isInvalid,
}) {
  const options = rosterStudents.map((student) => ({
    id: student.id,
    label: `${student.firstName} ${student.lastName}`,
  }));
 
  return (
    <Typeahead
      id="rosterStudentId"
      inputProps={{ "data-testid": "RosterStudentDropdown" }}
      options={options}
      placeholder="Select a student..."
      isInvalid={isInvalid}
      onChange={(selected) => {
        if (selected.length > 0) {
          setValue("rosterStudentId", selected[0].id, { shouldValidate: true });
        } else {
          setValue("rosterStudentId", "", { shouldValidate: true });
        }
      }}
    />
  );
}