mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Selectmenu: cleanup and small improvements
This commit is contained in:
parent
62ba812af9
commit
4bbfc2fd96
25
ui/jquery.ui.selectmenu.js
vendored
25
ui/jquery.ui.selectmenu.js
vendored
@ -130,7 +130,7 @@ $.widget( "ui.selectmenu", {
|
|||||||
|
|
||||||
if ( that.isOpen ) {
|
if ( that.isOpen ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
that.close( event, true);
|
that.close( event );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
focus: function( event, ui ) {
|
focus: function( event, ui ) {
|
||||||
@ -178,8 +178,9 @@ $.widget( "ui.selectmenu", {
|
|||||||
this.menuItems.find( 'a' ).attr( 'role', 'option' );
|
this.menuItems.find( 'a' ).attr( 'role', 'option' );
|
||||||
|
|
||||||
// select current item
|
// select current item
|
||||||
this.menu.menu( "focus", null, this._getSelectedItem() );
|
var item = this._getSelectedItem();
|
||||||
this._setSelected();
|
this.menu.menu( "focus", null, item );
|
||||||
|
this._setSelected( item.data( "item.selectmenu" ) );
|
||||||
|
|
||||||
// set and transfer disabled state
|
// set and transfer disabled state
|
||||||
this._getCreateOptions();
|
this._getCreateOptions();
|
||||||
@ -234,19 +235,15 @@ $.widget( "ui.selectmenu", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
close: function( event, focus ) {
|
close: function( event ) {
|
||||||
if ( this.isOpen ) {
|
if ( this.isOpen ) {
|
||||||
this._toggleButtonStyle();
|
this._toggleButtonStyle();
|
||||||
|
|
||||||
this.menuWrap.removeClass( 'ui-selectmenu-open' );
|
this.menuWrap.removeClass( 'ui-selectmenu-open' );
|
||||||
this.menu.attr( "aria-hidden", true );
|
this.menu.attr( "aria-hidden", true );
|
||||||
this.button.attr( "aria-expanded", false );
|
this.button.attr( "aria-expanded", false );
|
||||||
|
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
|
|
||||||
if ( focus ) {
|
|
||||||
this.button.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._trigger( "close", event );
|
this._trigger( "close", event );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -374,10 +371,9 @@ $.widget( "ui.selectmenu", {
|
|||||||
|
|
||||||
_select: function( item, event ) {
|
_select: function( item, event ) {
|
||||||
var oldIndex = this.element[0].selectedIndex;
|
var oldIndex = this.element[0].selectedIndex;
|
||||||
|
|
||||||
// change native select element
|
// change native select element
|
||||||
this.element[0].selectedIndex = item.index;
|
this.element[0].selectedIndex = item.index;
|
||||||
this._setSelected();
|
this._setSelected( item );
|
||||||
this._trigger( "select", event, { item: item } );
|
this._trigger( "select", event, { item: item } );
|
||||||
|
|
||||||
if ( item.index != oldIndex ) {
|
if ( item.index != oldIndex ) {
|
||||||
@ -385,11 +381,10 @@ $.widget( "ui.selectmenu", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setSelected: function() {
|
_setSelected: function( item ) {
|
||||||
var item = this._getSelectedItem(),
|
var link = item.element.find("a");
|
||||||
link = item.find("a");
|
|
||||||
// update button text
|
// update button text
|
||||||
this.button.button( "option", "label", item.text() );
|
this.button.button( "option", "label", item.label );
|
||||||
// change ARIA attr
|
// change ARIA attr
|
||||||
this.button.add( this.menu ).attr( "aria-activedescendant" , link.attr( "id" ) );
|
this.button.add( this.menu ).attr( "aria-activedescendant" , link.attr( "id" ) );
|
||||||
this.menuItems.find("a").attr( "aria-selected", false );
|
this.menuItems.find("a").attr( "aria-selected", false );
|
||||||
|
Loading…
Reference in New Issue
Block a user