-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from gosh-dre/custom-multi-select
Allow multiple reasons for test
- Loading branch information
Showing
11 changed files
with
593 additions
and
55 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { FieldProps } from "formik"; | ||
import Select from "react-select"; | ||
|
||
interface Option { | ||
label: string; | ||
value: string; | ||
} | ||
|
||
interface Props extends FieldProps { | ||
options: Option[]; | ||
isMulti: boolean; | ||
className?: string; | ||
placeholder?: string; | ||
} | ||
|
||
const CustomSelectField = ({ className, placeholder, field, form, options, isMulti = false }: Props) => { | ||
const onChange = (option: Option | Option[]) => { | ||
form.setFieldValue( | ||
field.name, | ||
isMulti ? (option as Option[]).map((item: Option) => item.value) : (option as Option).value, | ||
); | ||
}; | ||
|
||
const getValue = () => { | ||
if (options) { | ||
return isMulti | ||
? options.filter((option: any) => field?.value?.indexOf(option.value) >= 0) | ||
: options.find((option: any) => option.value === field.value); | ||
} else { | ||
return isMulti ? [] : ("" as any); | ||
} | ||
}; | ||
|
||
return ( | ||
<Select | ||
inputId={field.name} | ||
className={className} | ||
name={field.name} | ||
value={getValue()} | ||
onChange={onChange} | ||
placeholder={placeholder} | ||
options={options} | ||
isMulti={isMulti} | ||
/> | ||
); | ||
}; | ||
|
||
export default CustomSelectField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters