@@ -25,6 +25,7 @@ define( [
25
25
var extendSelect = function ( widget ) {
26
26
27
27
var select = widget . select ,
28
+ origDestroy = widget . _destroy ,
28
29
selectID = widget . selectID ,
29
30
label = widget . label ,
30
31
thisPage = widget . select . closest ( ".ui-page" ) ,
@@ -94,6 +95,17 @@ define( [
94
95
// Create list from select, update state
95
96
self . refresh ( ) ;
96
97
98
+ if ( self . _origTabIndex === undefined ) {
99
+ self . _origTabIndex = self . select . attr ( "tabindex" ) ;
100
+ // Map undefined to false, because self._origTabIndex === undefined
101
+ // indicates that we have not yet checked whether the select has
102
+ // originally had a tabindex attribute, whereas false indicates that
103
+ // we have checked the select for such an attribute, and have found
104
+ // none present.
105
+ if ( self . _origTabIndex === undefined ) {
106
+ self . _origTabIndex = false ;
107
+ }
108
+ }
97
109
self . select . attr ( "tabindex" , "-1" ) . focus ( function ( ) {
98
110
$ ( this ) . blur ( ) ;
99
111
self . button . focus ( ) ;
@@ -458,7 +470,12 @@ define( [
458
470
needPlaceholder = false ;
459
471
isPlaceholderItem = true ;
460
472
461
- // If we have identified a placeholder, mark it retroactively in the select as well
473
+ // If we have identified a placeholder, record the fact that it was
474
+ // us who have added the placeholder to the option and mark it
475
+ // retroactively in the select as well
476
+ if ( ! option . hasAttribute ( dataPlaceholderAttr ) ) {
477
+ this . _removePlaceholderAttr = true ;
478
+ }
462
479
option . setAttribute ( dataPlaceholderAttr , true ) ;
463
480
if ( o . hidePlaceholderMenuItems ) {
464
481
classes . push ( "ui-selectmenu-placeholder" ) ;
@@ -509,6 +526,30 @@ define( [
509
526
// TODO value is undefined at creation
510
527
"aria-owns" : this . menuId
511
528
} ) ;
529
+ } ,
530
+
531
+ _destroy : function ( ) {
532
+ this . close ( ) ;
533
+
534
+ // Restore the tabindex attribute to its original value
535
+ if ( this . _origTabIndex !== undefined ) {
536
+ if ( this . _origTabIndex !== false ) {
537
+ this . select . attr ( "tabindex" , this . _origTabIndex ) ;
538
+ } else {
539
+ this . select . removeAttr ( "tabindex" ) ;
540
+ }
541
+ }
542
+
543
+ // Remove the placeholder attribute if we were the ones to add it
544
+ if ( this . _removePlaceholderAttr ) {
545
+ this . _selectOptions ( ) . removeAttr ( "data-" + $ . mobile . ns + "placeholder" ) ;
546
+ }
547
+
548
+ // Remove the popup
549
+ this . listbox . remove ( ) ;
550
+
551
+ // Chain up
552
+ origDestroy . apply ( this , arguments ) ;
512
553
}
513
554
} ) ;
514
555
} ;
0 commit comments