@@ -25,6 +25,7 @@ define( [
2525 var extendSelect = function ( widget ) {
2626
2727 var select = widget . select ,
28+ origDestroy = widget . _destroy ,
2829 selectID = widget . selectID ,
2930 label = widget . label ,
3031 thisPage = widget . select . closest ( ".ui-page" ) ,
@@ -97,6 +98,17 @@ define( [
9798 // Create list from select, update state
9899 self . refresh ( ) ;
99100
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+ }
100112 self . select . attr ( "tabindex" , "-1" ) . focus ( function ( ) {
101113 $ ( this ) . blur ( ) ;
102114 self . button . focus ( ) ;
@@ -461,7 +473,12 @@ define( [
461473 needPlaceholder = false ;
462474 isPlaceholderItem = true ;
463475
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+ }
465482 option . setAttribute ( dataPlaceholderAttr , true ) ;
466483 if ( o . hidePlaceholderMenuItems ) {
467484 classes . push ( "ui-selectmenu-placeholder" ) ;
@@ -512,6 +529,30 @@ define( [
512529 // TODO value is undefined at creation
513530 "aria-owns" : this . menuId
514531 } ) ;
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 ) ;
515556 }
516557 } ) ;
517558 } ;
0 commit comments