Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import tabbable from 'tabbable';
const div = document.createElement('div');
const tabbables: Array = tabbable(div, {
includeContainer: true,
});
tabbable(div);
tabbables.map(node => node.nodeName);
const isTabbable: boolean = tabbable.isTabbable(document.createElement('a'));
const isFocusable: boolean = tabbable.isFocusable(
document.createElement('button')
);
const untouchabilityChecker = new (class {
hasDisplayNone() {
return true;
}
isUntouchable() {
return false;
}
})();
const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
document.createElement('a'),
untouchabilityChecker
);
document.createElement('a'),
untouchabilityChecker
);
const isFocusableWithUntouchabilityChecker: boolean = tabbable.isFocusable(
document.createElement('button'),
untouchabilityChecker
);
const isFocusable2: boolean = tabbable.isFocusable(
document.createElement('button'),
// $ExpectError
3
);
const isTabbable2: boolean = tabbable.isFocusable(
document.createElement('button'),
// $ExpectError
3
);
const untouchabilityChecker = new (class {
hasDisplayNone() {
return true;
}
isUntouchable() {
return false;
}
})();
const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
document.createElement('a'),
untouchabilityChecker
);
const isFocusableWithUntouchabilityChecker: boolean = tabbable.isFocusable(
document.createElement('button'),
untouchabilityChecker
);
const isFocusable2: boolean = tabbable.isFocusable(
document.createElement('button'),
// $ExpectError
3
);
const isTabbable2: boolean = tabbable.isFocusable(
document.createElement('button'),
// $ExpectError
3
);
function checkPointerDown(e) {
if (container.contains(e.target)) return;
if (config.clickOutsideDeactivates) {
deactivate({
returnFocus: !tabbable.isFocusable(e.target)
});
return;
}
// This is needed for mobile devices.
// (If we'll only let `click` events through,
// then on mobile they will be blocked anyways if `touchstart` is blocked.)
if (config.allowOutsideClick && config.allowOutsideClick(e)) {
return;
}
e.preventDefault();
}
private checkPointerDown(e): void {
if (this.container.contains(e.target)) return;
if (this.config.clickOutsideDeactivates) {
this.deactivate({
returnFocus: !tabbable.isFocusable(e.target)
});
return;
}
// This is needed for mobile devices.
// (If we'll only let `click` events through,
// then on mobile they will be blocked anyways if `touchstart` is blocked.)
if (this.config.allowOutsideClick && this.config.allowOutsideClick(e)) {
return;
}
e.preventDefault();
}
function checkPointerDown(e) {
if (container.contains(e.target)) return;
if (config.clickOutsideDeactivates) {
deactivate({
returnFocus: !tabbable.isFocusable(e.target)
});
} else {
e.preventDefault();
}
}
export const getClosestFocusableElement = (current: HTMLElement | null): HTMLElement | null => {
if (!current) {
return null;
}
return tabbable.isFocusable(current) ? current : getClosestFocusableElement(current.parentElement);
};