Skip to content

Commit

Permalink
Fix an issue where Element#getStyle('height') returns null if the hei…
Browse files Browse the repository at this point in the history
…ght is set to "auto."
  • Loading branch information
tobie committed Sep 4, 2008
1 parent 919b952 commit ae707f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix an issue where Element#getStyle('height') returns null if the height is set to "auto." (kangax, jddalton)

* Add unit tests for Element#descendantOf. (jddalton)

* Form#serializeElements should not serialize file inputs. (kangax, Lonesome Boy)
Expand Down
2 changes: 1 addition & 1 deletion src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ Element.Methods = {
element = $(element);
style = style == 'float' ? 'cssFloat' : style.camelize();
var value = element.style[style];
if (!value) {
if (!value || value == 'auto') {
var css = document.defaultView.getComputedStyle(element, null);
value = css ? css[style] : null;
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/dom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ new Test.Unit.Runner({
this.assertEqual("14px", $('style_test_dimensions').getStyle('width'));
this.assertEqual("17px", $('style_test_dimensions').getStyle('height'));
}

// height/width could always be calculated if it's set to "auto" (Firefox)
this.assertNotNull($('auto_dimensions').getStyle('height'));
this.assertNotNull($('auto_dimensions').getStyle('width'));
},

testElementGetOpacity: function() {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/fixtures/dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,5 @@
<div id="anonymous_element_3"></div>
</div>

<div id='elementToViewportDimensions' style='display: none'></div>
<div id='elementToViewportDimensions' style='display: none'></div>
<div id="auto_dimensions" style="height:auto"></div>

0 comments on commit ae707f4

Please sign in to comment.