]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Hide the UI on destroy
authorPorter Clevidence <116387727+porterclev@users.noreply.github.com>
Mon, 5 Aug 2024 17:30:53 +0000 (10:30 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Aug 2024 17:30:53 +0000 (19:30 +0200)
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

tests/unit/datepicker/methods.js
ui/widgets/datepicker.js

index 32d61174885bb6ae7149ceb38be5ec81dac69cb7..ec83fb791b0c9045e4478d53cc07bf618d932418 100644 (file)
@@ -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" );
@@ -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" );
index 6057605721182f0107ac5f655b6e4491df424885..323723b893935cb617abbb7dfbc816717164fc93 100644 (file)
@@ -435,6 +435,7 @@ $.extend( Datepicker.prototype, {
                        $target.removeClass( this.markerClassName ).empty();
                }
 
+               $.datepicker._hideDatepicker();
                if ( datepicker_instActive === inst ) {
                        datepicker_instActive = null;
                        this._curInst = null;