Skip to content

CSS: Don't warn against .css( "z-index", numberValue ) in jQuery >=4 #439

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

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

mgol
Copy link
Member

@mgol mgol commented Jul 7, 2021

When used against jQuery Git (future jQuery 4), there were warnings when
.css() was used against z-index with a number value. This didn't make sense
as z-index never had px auto-appended. Commit
d25ecd6 was supposed to solve a similar problem
but it only worked fine for 3.x.

To make the warning not show up when used with jQuery >=4 we need to fill in
jQuery.cssNumber with the latest version from jQuery 3.x so that the same
properties are allowed to have number values used with .css().

With this PR, jQuery UI with jQuery git & jQuery Migrate shows no Migrate
warnings, similarly to what's already the case when jQuery 3.x-git is used.

Fixes gh-438

When used against jQuery Git (future jQuery 4), there were warnings when
`.css()` was used against `z-index` with a number value. This didn't make sense
as `z-index` never had `px` auto-appended. Commit
d25ecd6 was supposed to solve a similar problem
but it only worked fine for `3.x`.

To make the warning not show up when used with jQuery >=4 we need to fill in
`jQuery.cssNumber` with the latest version from jQuery 3.x so that the same
properties are allowed to have number values used with `.css()`.

Fixes jquerygh-438
@@ -62,7 +62,7 @@ QUnit.test( "jQuery.css with arrays", function( assert ) {

QUnit.test( "jQuery.css with numbers", function( assert ) {
var jQuery3OrOlder = compareVersions( jQuery.fn.jquery, "4.0.0" ) < 0,
whitelist = [
allowlist = [
Copy link
Member

Choose a reason for hiding this comment

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

👍

if ( !jQuery.cssNumber ) {
jQuery.cssNumber = {};
jQuery.cssNumber = {
Copy link
Member

Choose a reason for hiding this comment

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

Man we can never win. 😸

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 is not 100% necessary as Core doesn't need this object in 4.x; we could as well just enumerate allowlisted properties in Migrate. However, by doing it via jQuery.cssNumber we have the same Migrate code path for all jQuery versions and it's easier to copy the object from the 3.x-stable Core branch if there are any changes.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it seems easier to just copy over the list. It's an exposed object so who knows, maybe some software out there is looking at it and not just setting properties.

@mgol mgol merged commit bd8267b into jquery:main Jul 9, 2021
@mgol mgol deleted the css-number-jquery-4 branch July 9, 2021 12:44
@mgol
Copy link
Member Author

mgol commented Jul 9, 2021

Landed. I don't think we need to release at the moment as it only affects jQuery Git at the moment; by the time we release jQuery 4.0 we're likely to have another Migrate release for different reasons anyway.

@mgol mgol modified the milestones: 3.3.3, 3.4.0 Mar 14, 2022
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.

jQuery 4 warning: Number-typed values are deprecated for jQuery.fn.css ("z-index", value)
2 participants