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

Dimensions: fall back to offsetWidth/Height for inline elems #3577

Closed
wants to merge 1 commit into from

Conversation

timmywil
Copy link
Member

@timmywil timmywil commented Mar 18, 2017

Fixes gh-3571

Checklist

@mention-bot
Copy link

@timmywil, thanks for your PR! By analyzing the history of the files in this pull request, we identified @markelog, @jeresig and @brandonaaron to be potential reviewers.

@timmywil timmywil added this to the 3.2.1 milestone Mar 18, 2017
@timmywil
Copy link
Member Author

Will land today. Get your reviews in! Thanks.

src/css.js Outdated
// Fall back to offsetWidth/Height when value is "auto"
// This happens for inline elements with no explicit setting (gh-3571)
if ( val === "auto" ) {
val = elem[ "offset" + name.toUpperCase().slice( 0, 1 ) + name.slice( 1 ) ];
Copy link
Member

Choose a reason for hiding this comment

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

Why not name[0].toUpperCase()? It should be shorter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I'm used to this for the sake of old browsers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@@ -31,6 +30,7 @@ function curCSS( elem, name, computed ) {
// This is against the CSSOM draft spec:
// https://drafts.csswg.org/cssom/#resolved-values
if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
style = elem.style;
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for this change? Isn't it larger?

Copy link
Member Author

@timmywil timmywil Mar 18, 2017

Choose a reason for hiding this comment

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

No point in retrieving style before this block. I'd like to avoid accessing properties that we don't need.

assert.equal( $div.width(), 0, "Test border specified with pixels" );
testElement( $div );
// Test span/inline element
testElement( jQuery( "#display" ) );
Copy link
Member

Choose a reason for hiding this comment

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

This is risky; why not create a span here instead of relying on a global fixture?

Copy link
Member Author

Choose a reason for hiding this comment

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

It already relies on a global fixture for the div. I'm not sure the risk. If it gets removed, the test will fail.

Copy link
Member

Choose a reason for hiding this comment

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

If it gets removed the test will fail but if it got changed from a span to a div, it wouldn't, would it?

Copy link
Member

@mgol mgol Mar 18, 2017

Choose a reason for hiding this comment

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

If you don't want to use a span defined in place, how about at least adding an assertion that its computed display is inline? That would eliminate the risk.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, you convinced me. I will create the span inline.

// Fall back to offsetWidth/Height when value is "auto"
// This happens for inline elements with no explicit setting (gh-3571)
if ( val === "auto" ) {
val = elem[ "offset" + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
Copy link
Member

Choose a reason for hiding this comment

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

elem[ jQuery.camelCase( "offset-" + name ) ] is probably smaller, but also probably not a big deal.

@timmywil timmywil closed this in 473d2ea Mar 20, 2017
@timmywil timmywil deleted the width branch March 20, 2017 16:16
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Regression: width() & height() return 0 for all inline elements
4 participants