@@ -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" ) ,
@@ -97,6 +98,17 @@ define( [
97
98
// Create list from select, update state
98
99
self . refresh ( ) ;
99
100
101
+ if ( self . _origTabIndex === undefined ) {
102
+ self . _origTabIndex = self . select . attr ( "tabindex" ) ;
103
+ // Map undefined to false, because self._origTabIndex === undefined
104
+ // indicates that we have not yet checked whether the select has
105
+ // originally had a tabindex attribute, whereas false indicates that
106
+ // we have checked the select for such an attribute, and have found
107
+ // none present.
108
+ if ( self . _origTabIndex === undefined ) {
109
+ self . _origTabIndex = false ;
110
+ }
111
+ }
100
112
self . select . attr ( "tabindex" , "-1" ) . focus ( function ( ) {
101
113
$ ( this ) . blur ( ) ;
102
114
self . button . focus ( ) ;
@@ -461,7 +473,12 @@ define( [
461
473
needPlaceholder = false ;
462
474
isPlaceholderItem = true ;
463
475
464
- // If we have identified a placeholder, mark it retroactively in the select as well
476
+ // If we have identified a placeholder, record the fact that it was
477
+ // us who have added the placeholder to the option and mark it
478
+ // retroactively in the select as well
479
+ if ( ! option . hasAttribute ( dataPlaceholderAttr ) ) {
480
+ this . _removePlaceholderAttr = true ;
481
+ }
465
482
option . setAttribute ( dataPlaceholderAttr , true ) ;
466
483
if ( o . hidePlaceholderMenuItems ) {
467
484
classes . push ( "ui-selectmenu-placeholder" ) ;
@@ -512,6 +529,30 @@ define( [
512
529
// TODO value is undefined at creation
513
530
"aria-owns" : this . menuId
514
531
} ) ;
532
+ } ,
533
+
534
+ _destroy : function ( ) {
535
+ this . close ( ) ;
536
+
537
+ // Restore the tabindex attribute to its original value
538
+ if ( this . _origTabIndex !== undefined ) {
539
+ if ( this . _origTabIndex !== false ) {
540
+ this . select . attr ( "tabindex" , this . _origTabIndex ) ;
541
+ } else {
542
+ this . select . removeAttr ( "tabindex" ) ;
543
+ }
544
+ }
545
+
546
+ // Remove the placeholder attribute if we were the ones to add it
547
+ if ( this . _removePlaceholderAttr ) {
548
+ this . _selectOptions ( ) . removeAttr ( "data-" + $ . mobile . ns + "placeholder" ) ;
549
+ }
550
+
551
+ // Remove the popup
552
+ this . listbox . remove ( ) ;
553
+
554
+ // Chain up
555
+ origDestroy . apply ( this , arguments ) ;
515
556
}
516
557
} ) ;
517
558
} ;
0 commit comments