Skip to content

Commit

Permalink
Datepicker: Hide the UI on destroy
Browse files Browse the repository at this point in the history
When the datepicker UI is shown and then destroyed programmatically:
```js
$( "#datepicker" ).datepicker( "destroy" );
```
hide the datepicker UI without the need for an explicit user action.
Previously, in 1.12 the UI would not disappear immediately but only after the
first `mousedown`. In later 1.13 versions, the UI would not disappear at all.

Fixes gh-2178
Closes gh-2268
  • Loading branch information
porterclev authored Aug 5, 2024
1 parent a0c5b12 commit 02a6e6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/unit/datepicker/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var beforeAfterEach = testHelper.beforeAfterEach;
QUnit.module( "datepicker: methods", beforeAfterEach() );

QUnit.test( "destroy", function( assert ) {
assert.expect( 35 );
assert.expect( 39 );
var inl,
inp = testHelper.init( "#inp" ),
dp = $( "#ui-datepicker-div" );
Expand All @@ -21,6 +21,15 @@ QUnit.test( "destroy", function( assert ) {
assert.equal( dp.css( "display" ), "block", "Datepicker - visible" );
inp.datepicker( "hide" ).datepicker( "destroy" );
assert.ok( $.datepicker._curInst == null, "Datepicker - destroyed and cleared reference" );
assert.equal( dp.css( "display" ), "none", "Datepicker - absent" );

// Destroy without manual hiding (ensure datepicker is hidden after calling destroy)
inp = testHelper.init( "#inp" );
inp.datepicker( "show" );
assert.equal( dp.css( "display" ), "block", "Datepicker - visible" );
inp.datepicker( "destroy" );
assert.ok( $.datepicker._curInst == null, "Datepicker - destroyed and cleared reference" );
assert.equal( dp.css( "display" ), "none", "Datepicker - absent" );

inp = testHelper.init( "#inp" );
assert.ok( inp.is( ".hasDatepicker" ), "Default - marker class set" );
Expand Down
1 change: 1 addition & 0 deletions ui/widgets/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ $.extend( Datepicker.prototype, {
$target.removeClass( this.markerClassName ).empty();
}

$.datepicker._hideDatepicker();
if ( datepicker_instActive === inst ) {
datepicker_instActive = null;
this._curInst = null;
Expand Down

0 comments on commit 02a6e6b

Please sign in to comment.