Skip to content

Commit 803bd81

Browse files
committed
Allow user to clear employer input
1 parent b025e1e commit 803bd81

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Components/forms/inputs/EmployerDropDown.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const EmployerDropDown = ({ arrayList, isEmpty, onChange, value }) => {
2323

2424
const handleChange = e =>
2525
onChange({
26-
target: { name: 'employer', type: 'text', value: e.value }
26+
target: {
27+
name: 'employer',
28+
type: 'text',
29+
value: e === null ? '' : e.value
30+
}
2731
})
2832

2933
return (
@@ -33,6 +37,7 @@ const EmployerDropDown = ({ arrayList, isEmpty, onChange, value }) => {
3337
className={isEmpty ? 'is-empty' : ''}
3438
inputId="employer"
3539
isSearchable
40+
isClearable
3641
options={employersList}
3742
onChange={handleChange}
3843
onCreateOption={newEmployer => {

src/Components/forms/inputs/EmployerDropDown.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ describe('EmployerDropDown', () => {
165165
)
166166
})
167167

168+
it('can be cleared', async () => {
169+
const onChange = jest.fn()
170+
renderInForm({ employers: ['ABC', 'BBC', 'CBC'], onChange, value: 'BBC' })
171+
await selectEvent.clearAll(screen.getByLabelText(/who is your employer/i))
172+
expect(onChange).toHaveBeenCalledWith({
173+
target: { name: 'employer', type: 'text', value: '' }
174+
})
175+
})
176+
168177
/**
169178
* @param {HTMLElement} container
170179
*/

0 commit comments

Comments
 (0)