focusable
// https://github.com/medialize/ally.js/issues/20
const hasLinkParent = getParents({context: element}).some(
parent => parent.nodeName.toLowerCase() === 'a' && parent.hasAttribute('href')
);
if (hasLinkParent) {
return true;
}
}
// https://github.com/medialize/ally.js/issues/21
if (!except.scrollable && supports.focusScrollContainer) {
if (supports.focusScrollContainerWithoutOverflow) {
// Internet Explorer does will consider the scrollable area focusable
// if the element is a or a and it is in fact scrollable,
// regardless of the CSS overflow property
if (isScrollableContainer(element, nodeName)) {
return true;
}
} else if (hasCssOverflowScroll(style)) {
// Firefox requires proper overflow setting, IE does not necessarily
// https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
return true;
}
}
if (!except.flexbox && supports.focusFlexboxContainer && hasCssDisplayFlex(style)) {
// elements with display:flex are focusable in IE10-11
return true;
}
const parent = element.parentElement;
if (!except.scrollable && parent) {
const parentNodeName = parent.nodeName.toLowerCase();
const parentStyle = window.getComputedStyle(parent, null);
if (supports.focusScrollBody && isScrollableContainer(parent, nodeName, parentNodeName, parentStyle)) {
// scrollable bodies are focusable Internet Explorer
// https://github.com/medialize/ally.js/issues/21
return true;
}
// Children of focusable elements with display:flex are focusable in IE10-11
if (supports.focusChildrenOfFocusableFlexbox) {
if (hasCssDisplayFlex(parentStyle)) {
return true;
}
}
}
// NOTE: elements marked as inert are not focusable,
// but that property is not exposed to the DOM
// https://www.w3.org/TR/html5/editing.html#inert
return false;
}
// bind exceptions to an iterator callback
isFocusRelevantRules.except = function(except = {}) {
const isFocusRelevant = function(context) {
return isFocusRelevantRules({
context,
except,
});
};
isFocusRelevant.rules = isFocusRelevantRules;
return isFocusRelevant;
};
// provide isFocusRelevant(context) as default iterator callback
const isFocusRelevant = isFocusRelevantRules.except({});
export default isFocusRelevant;