Skip to content

Commit 890d441

Browse files
gibson042dmethvin
authored andcommitted
Effects: Don't overwrite display:none when .hide()ing hidden elements
Fixes #14848 Closes jquerygh-1548
1 parent 5a8f769 commit 890d441

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/effects.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,8 @@ function defaultPrefilter( elem, props, opts ) {
160160
// Set display property to inline-block for height/width
161161
// animations on inline elements that are having width/height animated
162162
display = jQuery.css( elem, "display" );
163-
// Get default display if display is currently "none"
164-
if ( display === "none" ) {
165-
display = defaultDisplay( elem.nodeName );
166-
}
167-
if ( display === "inline" &&
163+
// Test default display if display is currently "none"
164+
if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" &&
168165
jQuery.css( elem, "float" ) === "none" ) {
169166

170167
style.display = "inline-block";
@@ -196,6 +193,10 @@ function defaultPrefilter( elem, props, opts ) {
196193
}
197194
}
198195
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
196+
197+
// Any non-fx value stops us from restoring the original display value
198+
} else {
199+
display = undefined;
199200
}
200201
}
201202

@@ -238,6 +239,10 @@ function defaultPrefilter( elem, props, opts ) {
238239
}
239240
}
240241
}
242+
243+
// If this is a noop like .hide().hide(), restore an overwritten display value
244+
} else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
245+
style.display = display;
241246
}
242247
}
243248

test/unit/effects.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,19 @@ test( "hide, fadeOut and slideUp called on element width height and width = 0 sh
16201620
this.clock.tick( 400 );
16211621
});
16221622

1623+
test( "hide should not leave hidden inline elements visible (#14848)", 2, function() {
1624+
var el = jQuery("#simon1");
1625+
1626+
el.hide( 1, function() {
1627+
equal( el.css( "display" ), "none", "hidden" );
1628+
el.hide( 1, function() {
1629+
equal( el.css( "display" ), "none", "still hidden" );
1630+
});
1631+
});
1632+
1633+
this.clock.tick( 100 );
1634+
});
1635+
16231636
test( "Handle queue:false promises", 10, function() {
16241637
var foo = jQuery( "#foo" ).clone().addBack(),
16251638
step = 1;

0 commit comments

Comments
 (0)