Skip to content

Commit 4f19ae6

Browse files
committed
Selector: Properly implement :enabled/:disabled for select contents
SemVer patch Fixes gh-382 Ref jquery/jquery#3224 Ref 7999a01 Closes gh-384
1 parent b05a9d3 commit 4f19ae6

File tree

5 files changed

+112
-35
lines changed

5 files changed

+112
-35
lines changed

dist/sizzle.js

+47-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Released under the MIT license
77
* http://jquery.org/license
88
*
9-
* Date: 2016-02-23
9+
* Date: 2016-08-08
1010
*/
1111
(function( window ) {
1212

@@ -465,26 +465,54 @@ function createButtonPseudo( type ) {
465465
* @param {Boolean} disabled true for :disabled; false for :enabled
466466
*/
467467
function createDisabledPseudo( disabled ) {
468-
// Known :disabled false positives:
469-
// IE: *[disabled]:not(button, input, select, textarea, optgroup, option, menuitem, fieldset)
470-
// not IE: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable
468+
469+
// Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable
471470
return function( elem ) {
472471

473-
// Check form elements and option elements for explicit disabling
474-
return "label" in elem && elem.disabled === disabled ||
475-
"form" in elem && elem.disabled === disabled ||
472+
// Only certain elements can match :enabled or :disabled
473+
// https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled
474+
// https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled
475+
if ( "form" in elem ) {
476+
477+
// Check for inherited disabledness on relevant non-disabled elements:
478+
// * listed form-associated elements in a disabled fieldset
479+
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
480+
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled
481+
// * option elements in a disabled optgroup
482+
// https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled
483+
// All such elements have a "form" property.
484+
if ( elem.parentNode && elem.disabled === false ) {
485+
486+
// Option elements defer to a parent optgroup if present
487+
if ( "label" in elem ) {
488+
if ( "label" in elem.parentNode ) {
489+
return elem.parentNode.disabled === disabled;
490+
} else {
491+
return elem.disabled === disabled;
492+
}
493+
}
476494

477-
// Check non-disabled form elements for fieldset[disabled] ancestors
478-
"form" in elem && elem.disabled === false && (
479-
// Support: IE6-11+
480-
// Ancestry is covered for us
481-
elem.isDisabled === disabled ||
495+
// Support: IE 6 - 11
496+
// Use the isDisabled shortcut property to check for disabled fieldset ancestors
497+
return elem.isDisabled === disabled ||
482498

483-
// Otherwise, assume any non-<option> under fieldset[disabled] is disabled
484-
/* jshint -W018 */
485-
elem.isDisabled !== !disabled &&
486-
("label" in elem || !disabledAncestor( elem )) !== disabled
487-
);
499+
// Where there is no isDisabled, check manually
500+
/* jshint -W018 */
501+
elem.isDisabled !== !disabled &&
502+
disabledAncestor( elem ) === disabled;
503+
}
504+
505+
return elem.disabled === disabled;
506+
507+
// Try to winnow out elements that can't be disabled before trusting the disabled property.
508+
// Some victims get caught in our net (label, legend, menu, track), but it shouldn't
509+
// even exist on them, let alone have a boolean value.
510+
} else if ( "label" in elem ) {
511+
return elem.disabled === disabled;
512+
}
513+
514+
// Remaining elements are neither :enabled nor :disabled
515+
return false;
488516
};
489517
}
490518

@@ -1693,6 +1721,7 @@ function addCombinator( matcher, combinator, base ) {
16931721
return matcher( elem, context, xml );
16941722
}
16951723
}
1724+
return false;
16961725
} :
16971726

16981727
// Check against all ancestor/preceding elements
@@ -1737,6 +1766,7 @@ function addCombinator( matcher, combinator, base ) {
17371766
}
17381767
}
17391768
}
1769+
return false;
17401770
};
17411771
}
17421772

0 commit comments

Comments
 (0)