Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] element with display 'contents' is visible and is tabbable #969

Merged
merged 1 commit into from
Oct 14, 2022
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