UNPKG

vanillajs-datepicker

Version:

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks

21 lines (19 loc) 783 B
import {isActiveElement} from '../lib/dom.js'; import {findElementInEventPath} from '../lib/event.js'; import {unfocus} from './functions.js'; // for the `document` to delegate the events from outside the picker/input field export function onClickOutside(datepicker, ev) { const {element, picker} = datepicker; // check both picker's and input's activeness to make updateOnBlur work in // the cases where... // - picker is hidden by ESC key press → input stays focused // - input is unfocused by closing mobile keyboard → piker is kept shown if (!picker.active && !isActiveElement(element)) { return; } const pickerElem = picker.element; if (findElementInEventPath(ev, el => el === element || el === pickerElem)) { return; } unfocus(datepicker); }