Skip to content
Closed
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
18 changes: 13 additions & 5 deletions src/helpers/tabbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
* http://api.jqueryui.com/category/ui-core/
*/

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

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

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

Comment on lines +18 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the naming backwards? If the function returns true, the element does not overflow (either because its content is clipped or its content is actually 0x0 in size)

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

Expand All @@ -21,11 +30,10 @@ function hidesContents(element) {
try {
// Otherwise we need to check some styles
const style = window.getComputedStyle(element);
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";
const displayValue = style.getPropertyValue("display");
return displayValue !== DISPLAY_CONTENTS && (zeroSize
? hasElementOverflow(element, style)
: displayValue === DISPLAY_NONE);
Comment on lines +33 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd go with

return zeroSize
      ? displayValue !== DISPLAY_CONTENTS && hasElementOverflow(element, style)
      : displayValue === DISPLAY_NONE;

but that's mostly a matter of taste. Either way works.

} catch (exception) {
// eslint-disable-next-line no-console
console.warn("Failed to inspect element style");
Expand Down