Skip to content

Commit

Permalink
fix(DatePicker): add missing openCalendar click handler function (#…
Browse files Browse the repository at this point in the history
…4325)

* fix(DatePicker): open calendar on "end" range input icon click

* refactor(DatePicker): remove unnecessary else blocks

* test(DatePickerInput): add `openCalendar` icon click test
  • Loading branch information
emyarod authored and abbeyhrt committed Oct 22, 2019
1 parent 700f21d commit 15dead0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/react/src/components/DatePicker/DatePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ describe('DatePicker', () => {
});
});

describe('DatePickerInput', () => {
it('should call `openCalendar` on calendar icon click', () => {
const mockOpenCalendar = jest.fn();
const wrapper = mount(
<DatePickerInput
labelText="Date Picker label"
id="input-from"
openCalendar={mockOpenCalendar}
/>
);
wrapper.find('svg').simulate('click');
expect(mockOpenCalendar).toHaveBeenCalled();
});
});

describe('DatePickerSkeleton', () => {
describe('Renders as expected', () => {
const wrapper = shallow(<DatePickerSkeleton range />);
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,20 @@ export default class DatePicker extends Component {
ref: this.assignInputFieldRef,
openCalendar: this.openCalendar,
});
} else if (index === 1 && child.type === DatePickerInput) {
}
if (index === 1 && child.type === DatePickerInput) {
return React.cloneElement(child, {
datePickerType,
ref: this.assignToInputFieldRef,
openCalendar: this.openCalendar,
});
} else if (index === 0) {
}
if (index === 0) {
return React.cloneElement(child, {
ref: this.assignInputFieldRef,
});
} else if (index === 1) {
}
if (index === 1) {
return React.cloneElement(child, {
ref: this.assignToInputFieldRef,
});
Expand Down

0 comments on commit 15dead0

Please sign in to comment.