MCPcopy Index your code
hub / github.com/react-dates/react-dates / onFinalKeyDown

Method onFinalKeyDown

src/components/DayPicker.jsx:433–539  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

431 }
432
433 onFinalKeyDown(e) {
434 this.setState({ withMouseInteractions: false });
435
436 const {
437 onBlur,
438 onTab,
439 onShiftTab,
440 isRTL,
441 } = this.props;
442 const { focusedDate, showKeyboardShortcuts } = this.state;
443 if (!focusedDate) return;
444
445 const newFocusedDate = focusedDate.clone();
446
447 let didTransitionMonth = false;
448
449 // focus might be anywhere when the keyboard shortcuts panel is opened so we want to
450 // return it to wherever it was before when the panel was opened
451 const activeElement = getActiveElement();
452 const onKeyboardShortcutsPanelClose = () => {
453 if (activeElement) activeElement.focus();
454 };
455
456 switch (e.key) {
457 case 'ArrowUp':
458 e.preventDefault();
459 newFocusedDate.subtract(1, 'week');
460 didTransitionMonth = this.maybeTransitionPrevMonth(newFocusedDate);
461 break;
462 case 'ArrowLeft':
463 e.preventDefault();
464 if (isRTL) {
465 newFocusedDate.add(1, 'day');
466 } else {
467 newFocusedDate.subtract(1, 'day');
468 }
469 didTransitionMonth = this.maybeTransitionPrevMonth(newFocusedDate);
470 break;
471 case 'Home':
472 e.preventDefault();
473 newFocusedDate.startOf('week');
474 didTransitionMonth = this.maybeTransitionPrevMonth(newFocusedDate);
475 break;
476 case 'PageUp':
477 e.preventDefault();
478 newFocusedDate.subtract(1, 'month');
479 didTransitionMonth = this.maybeTransitionPrevMonth(newFocusedDate);
480 break;
481
482 case 'ArrowDown':
483 e.preventDefault();
484 newFocusedDate.add(1, 'week');
485 didTransitionMonth = this.maybeTransitionNextMonth(newFocusedDate);
486 break;
487 case 'ArrowRight':
488 e.preventDefault();
489 if (isRTL) {
490 newFocusedDate.subtract(1, 'day');

Callers

nothing calls this directly

Calls 8

getActiveElementFunction · 0.85
onBlurFunction · 0.70
onShiftTabFunction · 0.70
onTabFunction · 0.70

Tested by

no test coverage detected