Open
6FD6
Description
Context
findFocusable() implements a chain of jQuery methods. Sadly it does not care for the case, that the chain returns null, so that .sort can't be called on it.
This happens, if no item in $element.find() matches the given conditions.
t.find(...).filter(...).sort is not a function
// Functions pulled out to be referenceable from internals
function findFocusable($element) {
if(!$element) {return false; }
return $element.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(function() {
if (!$(this).is(':visible') || $(this).attr('tabindex') < 0) { return false; } //only have visible elements and those that have a tabindex greater or equal 0
return true;
})
.sort( function( a, b ) {
if ($(a).attr('tabindex') === $(b).attr('tabindex')) {
return 0;
}
let aTabIndex = parseInt($(a).attr('tabindex'), 10),
bTabIndex = parseInt($(b).attr('tabindex'), 10);
// Undefined is treated the same as 0
if (typeof $(a).attr('tabindex') === 'undefined' && bTabIndex > 0) {
return 1;
}
if (typeof $(b).attr('tabindex') === 'undefined' && aTabIndex > 0) {
return -1;
}
if (aTabIndex === 0 && bTabIndex > 0) {
return 1;
}
if (bTabIndex === 0 && aTabIndex > 0) {
return -1;
}
if (aTabIndex < bTabIndex) {
return -1;
}
if (aTabIndex > bTabIndex) {
return 1;
}
});
}
(foundation.util.keyboard.js)
What should happen?
.sort()
should not be called on null
...
What happens instead?
.sort()
is called on null
...
Possible Solution
Add an empty check before calling .sort() on the result of find().filter().
...
Test Case and/or Steps to Reproduce (for bugs)
Test Case:
How to reproduce:
1.
2.
3.
Context
...
Your Environment
- Foundation version(s) used:
- Browser(s) name and version(s):
- Device, Operating System and version:
- Link to your project:
Checklist
- I have read and follow the CONTRIBUTING.md document.
- There are no other issues similar to this one.
- The issue title and template are correctly filled.
Metadata
Metadata
Assignees
Labels
No labels