Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/helpers/tabbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
* http://api.jqueryui.com/category/ui-core/
*/

const DISPLAY_NONE = "none";
const DISPLAY_CONTENTS = "contents";

const tabbableNode = /input|select|textarea|button|object|iframe/;

function isNotOverflowing(element, style) {
return (
style.getPropertyValue("overflow") !== "visible" ||
// if 'overflow: visible' set, check if there is actually any overflow
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
);
}

function hidesContents(element) {
const zeroSize = element.offsetWidth <= 0 && element.offsetHeight <= 0;

Expand All @@ -21,11 +32,10 @@ function hidesContents(element) {
try {
// Otherwise we need to check some styles
const style = window.getComputedStyle(element);
const displayValue = style.getPropertyValue("display");
return zeroSize
? style.getPropertyValue("overflow") !== "visible" ||
// if 'overflow: visible' set, check if there is actually any overflow
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
: style.getPropertyValue("display") == "none";
? displayValue !== DISPLAY_CONTENTS && isNotOverflowing(element, style)
: displayValue === DISPLAY_NONE;
} catch (exception) {
// eslint-disable-next-line no-console
console.warn("Failed to inspect element style");
Expand Down Expand Up @@ -68,9 +78,10 @@ export default function findTabbableDescendants(element) {
const descendants = [].slice
.call(element.querySelectorAll("*"), 0)
.reduce(
(finished, el) => finished.concat(
!el.shadowRoot ? [el] : findTabbableDescendants(el.shadowRoot)
),
(finished, el) =>
finished.concat(
!el.shadowRoot ? [el] : findTabbableDescendants(el.shadowRoot)
),
[]
);
return descendants.filter(tabbable);
Expand Down