File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ export default class DayPicker extends Component {
300300 focusPreviousDay ( dayNode ) {
301301 const dayNodes = Helpers . getDayNodes ( this . dayPicker , this . props . classNames ) ;
302302 const dayNodeIndex = Helpers . nodeListToArray ( dayNodes ) . indexOf ( dayNode ) ;
303-
303+ if ( dayNodeIndex === - 1 ) return ;
304304 if ( dayNodeIndex === 0 ) {
305305 this . showPreviousMonth ( ( ) => this . focusLastDayOfMonth ( ) ) ;
306306 } else {
@@ -311,7 +311,7 @@ export default class DayPicker extends Component {
311311 focusNextDay ( dayNode ) {
312312 const dayNodes = Helpers . getDayNodes ( this . dayPicker , this . props . classNames ) ;
313313 const dayNodeIndex = Helpers . nodeListToArray ( dayNodes ) . indexOf ( dayNode ) ;
314-
314+ if ( dayNodeIndex === - 1 ) return ;
315315 if ( dayNodeIndex === dayNodes . length - 1 ) {
316316 this . showNextMonth ( ( ) => this . focusFirstDayOfMonth ( ) ) ;
317317 } else {
Original file line number Diff line number Diff line change @@ -258,6 +258,11 @@ describe('DayPicker’s methods', () => {
258258 expect ( document . activeElement . innerHTML ) . toBe ( '31' ) ;
259259 expect ( instance . state . currentMonth . getMonth ( ) ) . toBe ( 4 ) ;
260260 } ) ;
261+ it ( 'should not throw an error when the node is not found' , ( ) => {
262+ expect ( ( ) =>
263+ instance . focusPreviousDay ( document . createElement ( 'div' ) )
264+ ) . not . toThrow ( ) ;
265+ } ) ;
261266 } ) ;
262267
263268 describe ( 'focusNextDay()' , ( ) => {
@@ -301,6 +306,11 @@ describe('DayPicker’s methods', () => {
301306 expect ( document . activeElement . innerHTML ) . toBe ( '1' ) ;
302307 expect ( instance . state . currentMonth . getMonth ( ) ) . toBe ( 2 ) ;
303308 } ) ;
309+ it ( 'should not throw an error when the node is not found' , ( ) => {
310+ expect ( ( ) =>
311+ instance . focusNextDay ( document . createElement ( 'div' ) )
312+ ) . not . toThrow ( ) ;
313+ } ) ;
304314 } ) ;
305315
306316 describe ( 'focusNextWeek()' , ( ) => {
You can’t perform that action at this time.
0 commit comments