Skip to content

Commit

Permalink
fix(DatePicker): Add explicit button type
Browse files Browse the repository at this point in the history
Prevents submission of parent form - default button type is `submit`.
  • Loading branch information
m7kvqbe1 committed Jul 23, 2020
1 parent ff23da0 commit ab56979
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('DatePicker', () => {
let onBlur: (e: React.FormEvent) => void
let dateSpy: jest.SpyInstance
let days: string[]
let onSubmitSpy: (e: React.FormEvent) => void

beforeAll(() => {
dateSpy = jest
Expand Down Expand Up @@ -463,4 +464,25 @@ describe('DatePicker', () => {
)
})
})

describe('when the DatePicker is nested within a form', () => {
beforeEach(() => {
onSubmitSpy = jest.fn()
wrapper = render(
<form onSubmit={onSubmitSpy}>
<DatePicker />
</form>
)
})

describe('and the open/close button is clicked', () => {
beforeEach(() => {
wrapper.getByTestId('datepicker-input-button').click()
})

it('does not submit the form', () => {
expect(onSubmitSpy).not.toHaveBeenCalled()
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const DatePickerInput = forwardRef(
/>
</div>
<button
type="button"
className="rn-date-picker__end-adornment"
onClick={isOpen ? onClose : onFocus}
data-testid="datepicker-input-button"
Expand Down

0 comments on commit ab56979

Please sign in to comment.