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

Attributes: Restore boolean attribute & false setter treatment from 3.x #540

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mgol
Copy link
Member

@mgol mgol commented Oct 8, 2024

Restore & warn against:

  • boolean attributes set to something different than their lowercase names
  • boolean attributes queried when set to something different than their lowercase names
  • non-boolean non-ARIA attributes set to false

Fixes gh-504
Ref jquery/jquery#5452
Ref jquery/api.jquery.com#1243

@mgol mgol added this to the 3.6.0 milestone Oct 8, 2024
@mgol mgol self-assigned this Oct 8, 2024
Comment on lines +43 to +47
if ( jQueryVersionSince( "4.0.0" ) ) {
return name.toLowerCase();
}
return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

This works in jQuery 3.x because - while boolHooks being a fallback for boolean attributes if attrHooks[ name ] didn't exist would not get picked up here - boolHooks only handle a setter and we're in a getter here. The getter - if the get attr hook is missing or returns null - is handled via a call to jQuery.find.attr( elem, name ) which is Sizzle.attr( elem, name ), that defers to Sizzle.selectors.attrHandle, exposed to jQuery via jQuery.expr.attrHandle and that, in turn, is set for boolean attrs by jQuery.

@mgol
Copy link
Member Author

mgol commented Oct 28, 2024

@timmywil I introduced two changes here in a fixup commit:

  1. The extraBoolAttrValues check now lowercases the tested value.
  2. Tests for extraBoolAttrValues are added. They are only supported when running with jQuery 4.x, but I skipped the warning when running with 3.x (you can see it in added tests) for two reasons:
    1. I didn't want to warn against setting a valid value for which jQuery 4.0.0 adds support.
    2. If someone is setting the hidden value to "until-found" and that gets normalized to "hidden", that's a bug that an upgrade to jQuery 4.x will likely fix.

Let me know what you think.

Restore & warn against:
* boolean attributes set to something different than their lowercase names
* boolean attributes queried when set to something different than their
  lowercase names
* non-boolean non-ARIA attributes set to `false`

Fixes jquerygh-504
Ref jquery/jquery#5452
Ref jquery/api.jquery.com#1243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restore boolean attribute treatment from 3.x
2 participants