bootstrap-vue
Version:
With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens
43 lines (32 loc) • 1.57 kB
JavaScript
import { closest, getAttr, getById, matches, select } from '../../../utils/dom';
import { EVENT_FILTER } from './constants';
var TABLE_TAG_NAMES = ['TD', 'TH', 'TR']; // Returns `true` if we should ignore the click/double-click/keypress event
// Avoids having the user need to use `@click.stop` on the form control
var filterEvent = function filterEvent(evt) {
// Exit early when we don't have a target element
if (!evt || !evt.target) {
/* istanbul ignore next */
return false;
}
var el = evt.target; // Exit early when element is disabled or a table element
if (el.disabled || TABLE_TAG_NAMES.indexOf(el.tagName) !== -1) {
return false;
} // Ignore the click when it was inside a dropdown menu
if (closest('.dropdown-menu', el)) {
return true;
}
var label = el.tagName === 'LABEL' ? el : closest('label', el); // If the label's form control is not disabled then we don't propagate event
// Modern browsers have `label.control` that references the associated input, but IE 11
// does not have this property on the label element, so we resort to DOM lookups
if (label) {
var labelFor = getAttr(label, 'for');
var input = labelFor ? getById(labelFor) : select('input, select, textarea', label);
if (input && !input.disabled) {
return true;
}
} // Otherwise check if the event target matches one of the selectors in the
// event filter (i.e. anchors, non disabled inputs, etc.)
// Return `true` if we should ignore the event
return matches(el, EVENT_FILTER);
};
export default filterEvent;