diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2024-03-20 00:46:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-20 00:46:30 +0100 |
commit | 063831b6378d518f9870ec5c4f1e7d5d16e04f36 (patch) | |
tree | 766484c3ccca1ca0d7227bbed1a6f76dd75f0273 /test/unit/selector.js | |
parent | f80e78ef3e7ded1fc693465d02dfb07510ded0ab (diff) | |
download | jquery-063831b6378d518f9870ec5c4f1e7d5d16e04f36.tar.gz jquery-063831b6378d518f9870ec5c4f1e7d5d16e04f36.zip |
Attributes: Make `.attr( name, false )` remove for all non-ARIA attrs
The HTML spec defines boolean attributes:
https://html.spec.whatwg.org/#boolean-attributes
that often correlate with boolean properties. If the attribute is missing, it
correlates with the `false` property value, if it's present - the `true`
property value. The only valid values are an empty string or the attribute name.
jQuery tried to be helpful here and treated boolean attributes in a special way
in the `.attr()` API:
1. For the getter, as long as the attribute was present, it was returning the
attribute name lowercased, ignoring the value.
2. For the setter, it was removing the attribute when `false` was passed;
otherwise, it was ignoring the passed value and set the attribute -
interestingly, in jQuery `>=3` not lowercased anymore.
The problem is the spec occasionally converts boolean attributes into ones with
additional attribute values with special behavior - one such example is the new
`"until-found"` value for the `hidden` attribute. Our setter normalization
means passing those values is impossible with jQuery. Also, new boolean
attributes are introduced occasionally and jQuery cannot easily add them to the
list without incurring breaking changes.
This patch removes any special handling of boolean attributes - the getter
returns the value as-is and the setter sets the provided value.
To provide better backwards compatibility with the very frequent `false` value
provided to remove the attribute, this patch makes `false` trigger attribute
removal for ALL non-ARIA attributes. ARIA attributes are exempt from the rule
since many of them recognize `"false"` as a valid value with semantics different
than the attribute missing. To remove an ARIA attribute, use `.removeAttr()` or
pass `null` as the value to `.attr()` which doesn't have this exception.
Fixes gh-5388
Closes gh-5452
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
Diffstat (limited to 'test/unit/selector.js')
-rw-r--r-- | test/unit/selector.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/test/unit/selector.js b/test/unit/selector.js index 2a2481a05..419120e7d 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -948,10 +948,10 @@ QUnit.test( "pseudo - nth-last-of-type", function( assert ) { QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "pseudo - has", function( assert ) { assert.expect( 4 ); - assert.t( "Basic test", "p:has(a)", [ "firstp", "ap", "en", "sap" ] ); - assert.t( "Basic test (irrelevant whitespace)", "p:has( a )", [ "firstp", "ap", "en", "sap" ] ); - assert.t( "Nested with overlapping candidates", - "#qunit-fixture div:has(div:has(div:not([id])))", + assert.selectInFixture( "Basic test", "p:has(a)", [ "firstp", "ap", "en", "sap" ] ); + assert.selectInFixture( "Basic test (irrelevant whitespace)", "p:has( a )", [ "firstp", "ap", "en", "sap" ] ); + assert.selectInFixture( "Nested with overlapping candidates", + "div:has(div:has(div:not([id])))", [ "moretests", "t2037", "fx-test-group", "fx-queue" ] ); // Support: Safari 15.4+, Chrome 105+ |