Skip to content

Commit 7c74cc3

Browse files
committed
use react-select in the autofill drobdown
1 parent ca096f5 commit 7c74cc3

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

src/Components/forms/inputs/EmployerDropDown.js

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,30 @@
11
import React, { useState } from 'react'
22
import { Label } from 'reactstrap'
3-
import '../index.css'
3+
import Select from 'react-select'
44

55
const EmployerDropDown = ({ employerOnChange, isEmpty, arrayList }) => {
66
const [value, setValue] = useState('')
7-
const filteredEmployers = arrayList.filter(item => {
8-
const searchTerm = value.toLowerCase()
9-
const employer = item.name.toLowerCase()
10-
const matchSearch = employer.includes(searchTerm)
11-
return searchTerm && matchSearch && employer !== searchTerm
12-
})
137
const employerSorter = (a, b) => {
14-
const aIndex = a.name.toLowerCase().indexOf(value.toLowerCase())
15-
const bIndex = b.name.toLowerCase().indexOf(value.toLowerCase())
8+
const aIndex = a.value.toLowerCase().indexOf(value.toLowerCase())
9+
const bIndex = b.value.toLowerCase().indexOf(value.toLowerCase())
1610
return aIndex > bIndex ? 1 : aIndex < bIndex ? -1 : 0
1711
}
18-
19-
const onSearch = searchTerm => {
20-
setValue(searchTerm)
21-
employerOnChange(searchTerm)
22-
}
12+
const employersList = arrayList
13+
.map(item => ({
14+
value: item.name,
15+
label: item.name
16+
}))
17+
.sort(employerSorter)
2318
return (
2419
<div className="form-group">
25-
<Label htmlFor="employer">"Who is your employer?"</Label>
26-
<input
27-
className={`form-control ${isEmpty && 'is-empty'}`}
28-
type="text"
20+
<Label htmlFor="employer">Who is your employer?</Label>
21+
<Select
2922
id="employer"
30-
value={value}
31-
onChange={e => setValue(e.target.value)}
23+
onInputChange={inputVal => setValue(inputVal)}
24+
options={employersList}
25+
onChange={e => employerOnChange(e.value)}
3226
placeholder="Type your employer name here"
33-
autoComplete="no"
3427
/>
35-
<div className="options">
36-
{filteredEmployers.sort(employerSorter).map(item => (
37-
<option
38-
className="employer-option"
39-
onClick={() => {
40-
onSearch(item.name)
41-
}}
42-
onKeyDown={e => e.key === 'Enter' && onSearch(item.name)}
43-
key={item._id}
44-
tabIndex={0}
45-
>
46-
{item.name}
47-
</option>
48-
))}
49-
</div>
5028
</div>
5129
)
5230
}

0 commit comments

Comments
 (0)