Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/leo3friedman/dropdown keyboard interactable #61

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 15 additions & 42 deletions frontend/src/components/Dropdown.module.css
Original file line number Diff line number Diff line change
@@ -1,53 +1,26 @@
.dropDown {
cursor: pointer;
background-color: white;
font-size: 16px;
color: var(--color-ccidc-placeholder);
height: 40px;
width: 460px;
border-radius: 4px;
border: 1px solid #d8d8d8;
.select {
padding: 0.5rem 1rem;
width: 100%;
background-image: url("../assets/dropDownIcon.svg");
background-repeat: no-repeat, repeat;
background-position:
right 0.7em top 50%,
0 0;
}

.dpContent {
position: relative;
top: 25%;
width: 100%;
background: white;
gap: 1em;
border: 1px solid #d8d8d8;
font-size: 16px;
}

.dpItem {
padding: 10px;
border: 0.5px solid #d8d8d8;
color: black;
cursor: pointer;
}

.selectOne {
margin-left: 15px;
margin-top: 10px;
}
font: var(--font-body);
border-color: #d8d8d8;
border-radius: 0.25rem;

.selectedOption {
color: black;
margin-left: 15px;
margin-top: 10px;
/* hide arrow for Firefox */
-moz-appearance: none;
/* hide arrow for Chrome */
-webkit-appearance: none;
}

.dpItem:hover {
background-color: #ebebeb;
/* hide arrow for IE10 */
.select::-ms-expand {
display: none;
}

@media (max-width: 1250px) {
.dropDown {
width: 330px;
}
.select.unselected {
color: #b4b4b4;
}
80 changes: 37 additions & 43 deletions frontend/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,49 @@ import { useState } from "react";

import styles from "./Dropdown.module.css";

export function Dropdown(props: {
type DropdownProps = {
options: string[];
onSelect: (value: string) => void;
onSelect?: (value: string) => void;
required?: boolean;
}) {
const [selected, setSelected] = useState("Select One");
const [isActive, setIsActive] = useState(false);
};

const handleOptionClick = (option: string) => {
export function Dropdown(props: DropdownProps) {
const { options, onSelect, required } = props;

// default value must be "" for required prop to work, https://stackoverflow.com/a/6048891
const defaultSelected = "";

const [selected, setSelected] = useState(defaultSelected);

function onSelectChange(event: React.FormEvent) {
const element = event.target as HTMLSelectElement;
const option = element.value;
setSelected(option);
setIsActive(false);
props.onSelect(option);
};
if (onSelect) onSelect(option);
}

return (
<div
className={styles.dropDown}
onClick={() => {
setIsActive(!isActive);
}}
role="button"
tabIndex={0}
onKeyDown={() => {
setIsActive(!isActive);
}}
<select
className={`${styles.select} ${selected === defaultSelected ? styles.unselected : ""}`}
onChange={onSelectChange}
required={required}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smll thing; can we add a name attribute to this that could be passed in through the props?

defaultValue={defaultSelected}
>
<div className={selected === "Select One" ? styles.selectOne : styles.selectedOption}>
{selected ?? "Select One"}
</div>
{isActive && (
<div className={styles.dpContent}>
{props.options.map((option, index) => (
<div
onClick={() => {
handleOptionClick(option);
}}
className={styles.dpItem}
role="button"
tabIndex={0}
key={index}
onKeyDown={() => {
setIsActive(!isActive);
}}
>
{option}
</div>
))}
</div>
)}
</div>
<option
value={defaultSelected}
hidden={selected !== defaultSelected}
disabled
className={styles.defaultOption}
>
Select One
</option>

{options?.length &&
options.map((option) => (
<option key={option} value={option} className={styles.option}>
{option}
</option>
))}
</select>
);
}
30 changes: 2 additions & 28 deletions frontend/src/components/Step1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ type Step1Props = {
export function Step1({ onSubmit }: Step1Props) {
const [email, setEmail] = useState<string>("");
const [confirmEmail, setConfirmEmail] = useState<string>("");
const [gender, setGender] = useState("");
const [phoneType, setPhoneType] = useState("");

const handleGenderSelect = (option: string) => {
setGender(option);
};

const handlePhoneSelect = (option: string) => {
setPhoneType(option);
};

const handleConfirmEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setConfirmEmail(e.target.value);
Expand Down Expand Up @@ -144,15 +134,7 @@ export function Step1({ onSubmit }: Step1Props) {
<div className={styles.inputBox}>
<label htmlFor="gender" className={`${styles.inputTitle} ${styles.dropdownLabel}`}>
Gender<span className={styles.boldRed}>*</span>
<Dropdown options={genders} onSelect={handleGenderSelect}></Dropdown>
<input
className={styles.customDropDown}
type="text"
id="gender"
name="gender"
defaultValue={gender}
required
></input>
<Dropdown options={genders} required />
</label>
</div>
</div>
Expand Down Expand Up @@ -185,15 +167,7 @@ export function Step1({ onSubmit }: Step1Props) {
<div className={styles.inputBox}>
<label htmlFor="phoneType" className={`${styles.inputTitle} ${styles.dropdownLabel}`}>
Phone Type<span className={styles.boldRed}>*</span>
<Dropdown options={devices} onSelect={handlePhoneSelect}></Dropdown>
<input
className={styles.customDropDown}
type="text"
id="phoneType"
name="phoneType"
defaultValue={phoneType}
required
></input>
<Dropdown options={devices} required />
</label>
</div>
<div className={styles.inputBox}>
Expand Down
32 changes: 2 additions & 30 deletions frontend/src/components/Step2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ function ProfessionalAssociationSection() {
}

function NationalExamSection() {
const [exam, setExam] = useState("");

const handleExamSelect = (option: string) => {
setExam(option);
};

return (
<div>
<div className={styles.formSection}>
Expand All @@ -310,15 +304,7 @@ function NationalExamSection() {
className={`${styles.inputTitle} ${styles.dropdownLabel}`}
>
National Exam<span className={styles.boldRed}>*</span>
<Dropdown options={examList} onSelect={handleExamSelect}></Dropdown>
<input
className={styles.customDropDown}
type="text"
id="nationalExam"
name="nationalExam"
defaultValue={exam}
required
></input>
<Dropdown options={examList} required />
</label>
</div>
<div className={styles.inputBox}>
Expand Down Expand Up @@ -359,11 +345,6 @@ function NationalExamSection() {

function ICCCourses() {
const [courses, setCourses] = useState([{ id: 1 }]);
const [courseSelect, setCourseSelect] = useState("");

const handleCourseSelect = (option: string) => {
setCourseSelect(option);
};

const addCourse = () => {
setCourses((prevCourses) => [...prevCourses, { id: prevCourses.length + 1 }]);
Expand Down Expand Up @@ -418,16 +399,7 @@ function ICCCourses() {
>
Courses
<span className={styles.boldRed}>*</span>
<Dropdown options={courseList} onSelect={handleCourseSelect}></Dropdown>
{/* Add if dropDown Required */}
<input
className={styles.customDropDown}
type="text"
id={`iccCourse${index}`}
name={`iccCourse${index}`}
defaultValue={courseSelect}
required
></input>
<Dropdown options={courseList} required />
</label>
</div>
<div className={styles.inputBox}>
Expand Down
26 changes: 17 additions & 9 deletions frontend/src/components/Step4.module.css
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some CSS rule was removed that made the fields that impacted the flexing of elements when the screen is small.
image

Used to look like this
image

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
padding-bottom: 30px;
}

@media (max-width: 1300px) {
.formRow {
display: flex;
flex-direction: column;
align-items: center;
}
.formRow .input {
width: 330px;
}
.formRow .dropdownContainer {
width: 460px;
}

.sectionTitle {
Expand Down Expand Up @@ -65,6 +58,21 @@
color: var(--color-ccidc-placeholder);
}

@media (max-width: 1300px) {
.formRow {
display: flex;
flex-direction: column;
align-items: center;
}
.formRow .input {
width: 330px;
}

.formRow .dropdownContainer {
width: 330px;
}
}

.line {
border: 0.5px solid #d8d8d8;
margin-top: 30px;
Expand Down
13 changes: 3 additions & 10 deletions frontend/src/components/Step4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,9 @@ export const Step4: React.FC<StepProps> = ({ next }: StepProps) => {

<label htmlFor="dropDown" className={styles.label}>
Have you ever been convicted of a Felony?<span className={styles.red}>*</span>
<Dropdown options={["Yes", "No"]} onSelect={handleSelect}></Dropdown>
{/* Add if dropDown Required */}
<input
className={styles.customDropDown}
type="text"
id="dropDown"
name="dropDown"
value={selectedFelonyCharge}
required
></input>
<div className={styles.dropdownContainer}>
<Dropdown options={["Yes", "No"]} onSelect={handleSelect} required />
</div>
</label>
</div>

Expand Down
8 changes: 0 additions & 8 deletions frontend/src/components/Steps.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,3 @@ ul {
.dropdownLabel {
position: relative;
}
.customDropDown {
position: absolute;
bottom: 0.5rem;
left: 0.5rem;
/* Forcefully hide */
opacity: 0;
pointer-events: none;
}
11 changes: 1 addition & 10 deletions frontend/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { Application } from "./Application.tsx";
import { Candidates } from "./Candidates.tsx";
import { Login } from "./Login.tsx";
import { PrescreeningForm } from "./PrescreeningForm.tsx";
import { TestCongratulations } from "./TestCongratulations.tsx";
import { TestModals } from "./TestModals.tsx";
import { ThankyouForApplying } from "./ThankyouForApplying.tsx";
export {
Application,
Candidates,
TestCongratulations,
ThankyouForApplying,
PrescreeningForm,
Login,
TestModals,
};
export { Application, Candidates, ThankyouForApplying, PrescreeningForm, Login, TestModals };
Loading