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: Warn & restore boolean attribute & false setter treatment from 3.x #540

Merged
merged 2 commits into from
Nov 19, 2024

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.

@mgol mgol requested a review from timmywil October 28, 2024 23:22
mgol added 2 commits October 29, 2024 17:47
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
@mgol mgol merged commit 5471109 into jquery:main Nov 19, 2024
9 checks passed
@mgol mgol deleted the boolean-attrs branch November 19, 2024 21:39
@mgol mgol modified the milestones: 3.6.0, 4.0.0 Nov 19, 2024
@mgol mgol removed the Needs review label Nov 19, 2024
@mgol mgol changed the title Attributes: Restore boolean attribute & false setter treatment from 3.x Attributes: Warn & restore boolean attribute & false setter treatment from 3.x Nov 19, 2024
@mgol mgol modified the milestones: 4.0.0, 3.6.0 Nov 19, 2024
@mgol
Copy link
Member Author

mgol commented Nov 19, 2024

Landed on both main & 3.x-stable in 5471109; the main patch is tweaked in #555 and the 3.x-stable one in #554.

mgol added a commit to mgol/api.jquery.com that referenced this pull request Dec 16, 2024
mgol added a commit to jquery/api.jquery.com that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn & restore boolean attribute treatment from 3.x
2 participants