Selectmenu: re-enabled lazy loading of the menu items (menu refresh)

This commit is contained in:
Felix Nagel 2012-02-21 23:41:00 +01:00
parent d0c31c188e
commit 52e43c076f
3 changed files with 17 additions and 9 deletions

View File

@ -8,8 +8,10 @@ test("accessibility", function () {
menu = element.selectmenu("menuWidget").parent(),
link = button.find("a"),
selected = element.find("option:selected"),
ul = menu.children("ul"),
links = ul.find("li.ui-menu-item a");
ul = menu.children("ul");
link.simulate( "focus" );
var links = ul.find("li.ui-menu-item a");
expect(12 + links.length * 2);
@ -51,9 +53,11 @@ $.each([
menu = element.selectmenu("menuWidget").parent(),
link = button.find("a"),
ul = menu.children("ul"),
links = ul.find("li.ui-menu-item a"),
selected = element.find("option:selected");
link.simulate( "focus" )
var links = ul.find("li.ui-menu-item a");
link.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( ul.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "after keydown menu aria-activedescendant" );
equals( links.eq(element[0].selectedIndex).attr("aria-selected"), "true", "after keydown selected menu link aria-selected" );

View File

@ -23,7 +23,7 @@ test("change", function () {
menu = this.element.selectmenu("menuWidget").parent(),
value = this.element.find("option").first().text();
button.find("a").simulate( "click" );
button.find("a").simulate( "focus" ).simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).trigger( "click" );
});
@ -63,7 +63,7 @@ test("focus", function () {
var button = this.element.selectmenu("widget").parent(),
menu = this.element.selectmenu("menuWidget").parent();
button.find("a").simulate( "click" );
button.find("a").simulate( "focus" ).simulate( "click" );
menu.find(".ui-menu-item").simulate("mouseover");
});
@ -98,7 +98,7 @@ test("select", function () {
var button = this.element.selectmenu("widget").parent(),
menu = this.element.selectmenu("menuWidget").parent();
button.find("a").simulate( "click" );
button.find("a").simulate( "focus" ).simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).trigger("click");
});

View File

@ -54,7 +54,6 @@ $.widget( "ui.selectmenu", {
this._bind( this.button, this._buttonEvents );
this._drawMenu();
this.refresh();
if ( this.options.disabled ) {
this.disable();
@ -70,7 +69,7 @@ $.widget( "ui.selectmenu", {
// create button
this.button = $( '<a />', {
href: '#' + this.ids.id,
html: '&nbsp;',
html: this.element.find( "option:selected" ).text() || '&nbsp;',
tabindex: ( tabindex ? tabindex : this.options.disabled ? -1 : 0 ),
id: this.ids.button,
width: this.element.outerWidth(),
@ -316,6 +315,11 @@ $.widget( "ui.selectmenu", {
},
_buttonEvents: {
focus: function( event ) {
// init Menu on first focus
this.refresh();
this.button.unbind( "focus." + this.widgetName );
},
click: function( event ) {
this._toggle( event );
event.preventDefault();
@ -389,7 +393,7 @@ $.widget( "ui.selectmenu", {
_setSelected: function( item ) {
var link = this._getSelectedItem().find("a");
// update button text
this.button.button( "option", "label", item.label );
this.button.find( "span.ui-button-text" ).html( item.label );
// change ARIA attr
this.button.add( this.menu ).attr( "aria-activedescendant" , link.attr( "id" ) );
this.menuItems.find("a").attr( "aria-selected", false );