Skip to content

Commit

Permalink
Merge pull request gpbl#646 from gpbl/fix-630
Browse files Browse the repository at this point in the history
Fix error with focusing outside nodes
  • Loading branch information
gpbl committed Mar 5, 2018
2 parents 6ae71cc + 973a5f5 commit 8f1be54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DayPicker.js
Expand Up @@ -300,7 +300,7 @@ export default class DayPicker extends Component {
focusPreviousDay(dayNode) {
const dayNodes = Helpers.getDayNodes(this.dayPicker, this.props.classNames);
const dayNodeIndex = Helpers.nodeListToArray(dayNodes).indexOf(dayNode);

if (dayNodeIndex === -1) return;
if (dayNodeIndex === 0) {
this.showPreviousMonth(() => this.focusLastDayOfMonth());
} else {
Expand All @@ -311,7 +311,7 @@ export default class DayPicker extends Component {
focusNextDay(dayNode) {
const dayNodes = Helpers.getDayNodes(this.dayPicker, this.props.classNames);
const dayNodeIndex = Helpers.nodeListToArray(dayNodes).indexOf(dayNode);

if (dayNodeIndex === -1) return;
if (dayNodeIndex === dayNodes.length - 1) {
this.showNextMonth(() => this.focusFirstDayOfMonth());
} else {
Expand Down
10 changes: 10 additions & 0 deletions test/daypicker/methods.js
Expand Up @@ -258,6 +258,11 @@ describe('DayPicker’s methods', () => {
expect(document.activeElement.innerHTML).toBe('31');
expect(instance.state.currentMonth.getMonth()).toBe(4);
});
it('should not throw an error when the node is not found', () => {
expect(() =>
instance.focusPreviousDay(document.createElement('div'))
).not.toThrow();
});
});

describe('focusNextDay()', () => {
Expand Down Expand Up @@ -301,6 +306,11 @@ describe('DayPicker’s methods', () => {
expect(document.activeElement.innerHTML).toBe('1');
expect(instance.state.currentMonth.getMonth()).toBe(2);
});
it('should not throw an error when the node is not found', () => {
expect(() =>
instance.focusNextDay(document.createElement('div'))
).not.toThrow();
});
});

describe('focusNextWeek()', () => {
Expand Down

0 comments on commit 8f1be54

Please sign in to comment.