@@ -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" ) ,
@@ -94,6 +95,17 @@ define( [
9495 // Create list from select, update state
9596 self . refresh ( ) ;
9697
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+ }
97109 self . select . attr ( "tabindex" , "-1" ) . focus ( function ( ) {
98110 $ ( this ) . blur ( ) ;
99111 self . button . focus ( ) ;
@@ -458,7 +470,12 @@ define( [
458470 needPlaceholder = false ;
459471 isPlaceholderItem = true ;
460472
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+ }
462479 option . setAttribute ( dataPlaceholderAttr , true ) ;
463480 if ( o . hidePlaceholderMenuItems ) {
464481 classes . push ( "ui-selectmenu-placeholder" ) ;
@@ -509,6 +526,30 @@ define( [
509526 // TODO value is undefined at creation
510527 "aria-owns" : this . menuId
511528 } ) ;
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 ) ;
512553 }
513554 } ) ;
514555 } ;
0 commit comments