@limetech/lime-elements
Version:
82 lines (75 loc) • 2.45 kB
JavaScript
;
var _assignValue = require('./_assignValue-D2D1zedG.js');
/**
* This base implementation of `_.zipObject` which assigns values using `assignFunc`.
*
* @private
* @param {Array} props The property identifiers.
* @param {Array} values The property values.
* @param {Function} assignFunc The function to assign values.
* @returns {Object} Returns the new object.
*/
function baseZipObject(props, values, assignFunc) {
var index = -1,
length = props.length,
valsLength = values.length,
result = {};
while (++index < length) {
var value = index < valsLength ? values[index] : undefined;
assignFunc(result, props[index], value);
}
return result;
}
/**
* This method is like `_.fromPairs` except that it accepts two arrays,
* one of property identifiers and one of corresponding values.
*
* @static
* @memberOf _
* @since 0.4.0
* @category Array
* @param {Array} [props=[]] The property identifiers.
* @param {Array} [values=[]] The property values.
* @returns {Object} Returns the new object.
* @example
*
* _.zipObject(['a', 'b'], [1, 2]);
* // => { 'a': 1, 'b': 2 }
*/
function zipObject(props, values) {
return baseZipObject(props || [], values || [], _assignValue.assignValue);
}
const FOCUSABLE_SELECTOR = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
const isDisabled = (element) => {
return (element.disabled === true ||
element.hasAttribute('disabled') ||
element.getAttribute('aria-disabled') === 'true');
};
/**
* Focuses the first focusable element inside a trigger element.
* Supports custom elements by searching both the element's shadow root
* and its light DOM.
*
* @param trigger - The trigger element to focus.
* @returns `true` if focus was moved, otherwise `false`.
*/
const focusTriggerElement = (trigger) => {
var _a;
if (!trigger || isDisabled(trigger)) {
return false;
}
const shadowFocusable = (_a = trigger.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(FOCUSABLE_SELECTOR);
if (shadowFocusable) {
shadowFocusable.focus();
return true;
}
const lightDomFocusable = trigger.querySelector(FOCUSABLE_SELECTOR);
if (lightDomFocusable) {
lightDomFocusable.focus();
return true;
}
trigger.focus();
return true;
};
exports.focusTriggerElement = focusTriggerElement;
exports.zipObject = zipObject;