MCPcopy
hub / github.com/flatpickr/flatpickr / onKeyDown

Function onKeyDown

src/index.ts:1642–1815  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

1640 }
1641
1642 function onKeyDown(e: KeyboardEvent) {
1643 // e.key e.keyCode
1644 // "Backspace" 8
1645 // "Tab" 9
1646 // "Enter" 13
1647 // "Escape" (IE "Esc") 27
1648 // "ArrowLeft" (IE "Left") 37
1649 // "ArrowUp" (IE "Up") 38
1650 // "ArrowRight" (IE "Right") 39
1651 // "ArrowDown" (IE "Down") 40
1652 // "Delete" (IE "Del") 46
1653
1654 const eventTarget = getEventTarget(e);
1655 const isInput = self.config.wrap
1656 ? element.contains(eventTarget as HTMLElement)
1657 : eventTarget === self._input;
1658 const allowInput = self.config.allowInput;
1659 const allowKeydown = self.isOpen && (!allowInput || !isInput);
1660 const allowInlineKeydown = self.config.inline && isInput && !allowInput;
1661
1662 if (e.keyCode === 13 && isInput) {
1663 if (allowInput) {
1664 self.setDate(
1665 self._input.value,
1666 true,
1667 eventTarget === self.altInput
1668 ? self.config.altFormat
1669 : self.config.dateFormat
1670 );
1671 self.close();
1672 return (eventTarget as HTMLElement).blur();
1673 } else {
1674 self.open();
1675 }
1676 } else if (
1677 isCalendarElem(eventTarget as HTMLElement) ||
1678 allowKeydown ||
1679 allowInlineKeydown
1680 ) {
1681 const isTimeObj =
1682 !!self.timeContainer &&
1683 self.timeContainer.contains(eventTarget as HTMLElement);
1684
1685 switch (e.keyCode) {
1686 case 13:
1687 if (isTimeObj) {
1688 e.preventDefault();
1689 updateTime();
1690 focusAndClose();
1691 } else selectDate(e);
1692
1693 break;
1694
1695 case 27: // escape
1696 e.preventDefault();
1697 focusAndClose();
1698 break;
1699

Callers

nothing calls this directly

Calls 14

getEventTargetFunction · 0.90
isCalendarElemFunction · 0.85
updateTimeFunction · 0.85
focusAndCloseFunction · 0.85
selectDateFunction · 0.85
getClosestActiveElementFunction · 0.85
isInViewFunction · 0.85
focusOnDayFunction · 0.85
changeMonthFunction · 0.85
getFirstAvailableDayFunction · 0.85
changeYearFunction · 0.85
setHoursFromInputsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…