Skip to content

Commit

Permalink
Selectmenu: re-enabled lazy loading of the menu items (menu refresh)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnagel committed Feb 21, 2012
1 parent d0c31c1 commit 52e43c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions tests/unit/selectmenu/selectmenu_core.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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" );
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/selectmenu/selectmenu_events.js
Expand Up @@ -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" );
});

Expand Down Expand Up @@ -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");
});

Expand Down Expand Up @@ -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");
});

Expand Down
10 changes: 7 additions & 3 deletions ui/jquery.ui.selectmenu.js
Expand Up @@ -54,7 +54,6 @@ $.widget( "ui.selectmenu", {
this._bind( this.button, this._buttonEvents );

this._drawMenu();
this.refresh();

if ( this.options.disabled ) {
this.disable();
Expand All @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 52e43c0

Please sign in to comment.