Skip to content

Commit

Permalink
use placeholder, change select border color
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelaZQ1 committed Feb 7, 2024
1 parent d4846d5 commit baaed44
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
28 changes: 15 additions & 13 deletions packages/frontend/components/Form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type PlanSelectProps = {
/** Are the field values numbers. */
isNumeric?: boolean;
isSearchable?: boolean;
/** An option in the select dropdown that indicates "no selection". */
noValueOptionLabel?: string;
/** The default text shown in the input box. */
placeholder?: string;
/** Fuzzy options to use */
useFuzzySearch?: boolean;
};
Expand All @@ -41,7 +41,7 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
rules,
isNumeric,
isSearchable,
noValueOptionLabel,
placeholder,
useFuzzySearch,
}) => {
const filterOptions = useFuzzySearch
Expand Down Expand Up @@ -73,12 +73,6 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
label: val,
}));

let noValueOption;
if (noValueOptionLabel) {
noValueOption = { value: null, label: noValueOptionLabel };
selectOptions.unshift(noValueOption);
}

const onChange = (option: any) => {
let val = option ? option.value : null;
onChangeSideEffect && onChangeSideEffect(val);
Expand All @@ -94,9 +88,16 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
if (isNumeric) {
selectedValue = value ? value.toString() : null;
}
const selectedOption =
selectOptions.find((option: any) => option.value === selectedValue) ??
noValueOption;
const selectedOption = selectOptions.find(
(option: any) => option.value === selectedValue
);

const styles = {
control: (baseStyles: any, state: { isFocused: any }) => ({
...baseStyles,
borderColor: state.isFocused ? "neutral.200" : "neutral.100",
}),
};

return (
<FormControl isInvalid={error != null}>
Expand All @@ -109,11 +110,12 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
{label}
</FormLabel>
<Select
styles={styles}
options={selectOptions}
onChange={onChange}
value={selectedOption}
isSearchable={isSearchable}
defaultValue={noValueOption}
placeholder={placeholder}
filterOption={filterOptions}
{...fieldRest}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/components/Plan/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
<>
<PlanSelect
label="Catalog Year"
noValueOptionLabel="Select a Catalog Year"
placeholder="Select a Catalog Year"
name="catalogYear"
control={control}
options={extractSupportedMajorYears(supportedMajorsData)}
Expand Down Expand Up @@ -232,7 +232,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
/>
<PlanSelect
label="Major"
noValueOptionLabel="Select a Major"
placeholder="Select a Major"
name="major"
control={control}
options={extractSupportedMajorNames(
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/components/Plan/EditPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const EditPlanModal: React.FC<EditPlanModalProps> = ({ plan }) => {
<>
<PlanSelect
label="Catalog Year"
noValueOptionLabel="Select a Catalog Year"
placeholder="Select a Catalog Year"
name="catalogYear"
control={control}
options={extractSupportedMajorYears(supportedMajorsData)}
Expand Down Expand Up @@ -256,7 +256,7 @@ export const EditPlanModal: React.FC<EditPlanModalProps> = ({ plan }) => {
/>
<PlanSelect
label="Major"
noValueOptionLabel="Select a Major"
placeholder="Select a Major"
name="major"
control={control}
options={extractSupportedMajorNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const PlanConcentrationsSelect: React.FC<

return (
<PlanSelect
label="Concentrations"
noValueOptionLabel="Select a Concentration"
label="Concentration"
placeholder="Select a Concentration"
name="concentration"
options={supportedMajor.concentrations}
control={control}
Expand Down

0 comments on commit baaed44

Please sign in to comment.