@progress/kendo-angular-layout
Version:
Kendo UI for Angular Layout Package - a collection of components to create professional application layoyts
48 lines (47 loc) • 1.74 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { isPresent } from '../common/util';
const focusableRegex = /^(?:a|input|select|option|textarea|button|object)$/i;
const toClassList = (classNames) => String(classNames).trim().split(' ');
/**
* @hidden
*/
export const isFocusable = (element) => {
if (element.tagName) {
const tagName = element.tagName.toLowerCase();
const tabIndex = element.getAttribute('tabindex');
const skipTab = tabIndex === '-1';
let focusable = tabIndex !== null && !skipTab;
if (focusableRegex.test(tagName)) {
focusable = !element.disabled && !skipTab;
}
return focusable;
}
return false;
};
/**
* @hidden
*/
export const hasClass = (element, className) => Boolean(toClassList(element.className).find((name) => name === className));
/**
* @hidden
*/
export const closestInScope = (target, predicate, scope, targetAttr) => {
while (target && target !== scope && !predicate(target, targetAttr)) {
target = target.parentNode;
}
if (target !== scope) {
return target;
}
};
/**
* @hidden
*/
export const itemIndex = (item, indexAttr) => +item.getAttribute(indexAttr);
const hasItemIndex = (item, indexAttr) => isPresent(item.getAttribute(indexAttr));
/**
* @hidden
*/
export const closestItem = (target, targetAttr, scope) => closestInScope(target, hasItemIndex, scope, targetAttr);