Skip to content

Commit

Permalink
Menu: Fix menubar tab and focus handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Mar 17, 2011
1 parent a077047 commit 4a04ad2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/visual/menu/menubar.html
Expand Up @@ -52,7 +52,7 @@
} }


/* menubar styles */ /* menubar styles */
.ui-menubar .ui-button { float: left; font-weight: normal; border-top-width: 0 !important; border-bottom-width: 0 !important; margin: 0; } .ui-menubar .ui-button { float: left; font-weight: normal; border-top-width: 0 !important; border-bottom-width: 0 !important; margin: 0; outline: none; }
.ui-menubar .ui-menubar-link { border-right: 1px dashed transparent; border-left: 1px dashed transparent; } .ui-menubar .ui-menubar-link { border-right: 1px dashed transparent; border-left: 1px dashed transparent; }


table { table {
Expand Down
23 changes: 14 additions & 9 deletions tests/visual/menu/menubar.js
Expand Up @@ -17,7 +17,7 @@ $.widget("ui.menubar", {
var o = this.options; var o = this.options;


this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix'); this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix');

this._focusable(items);
items.next("ul").each(function(i, elm) { items.next("ul").each(function(i, elm) {
$(elm).menu({ $(elm).menu({
select: function(event, ui) { select: function(event, ui) {
Expand All @@ -38,11 +38,12 @@ $.widget("ui.menubar", {
self.right(event); self.right(event);
event.preventDefault(); event.preventDefault();
break; break;
case $.ui.keyCode.TAB:
self[ event.shiftKey ? "left" : "right" ]( event );
event.preventDefault();
break;
}; };
}).blur(function() {
$(this).hide().prev().removeClass("ui-state-active").removeAttr("tabIndex");
self.timer = setTimeout(function() {
self.open = false;
}, 13);
}); });
}); });
items.each(function() { items.each(function() {
Expand All @@ -56,7 +57,7 @@ $.widget("ui.menubar", {
self._close(); self._close();
return; return;
} }
if (menu.length && (!/^mouse/.test(event.type) || self.active && self.active.is(":visible") )) { if (menu.length && (self.open || event.type == "click")) {
self._open(event, menu); self._open(event, menu);
} }
}) })
Expand All @@ -81,15 +82,19 @@ $.widget("ui.menubar", {


_close: function() { _close: function() {
this.items.next("ul").hide(); this.items.next("ul").hide();
this.items.removeClass("ui-state-active"); this.items.removeClass("ui-state-active").removeAttr("tabIndex");
this.open = false;
}, },


_open: function(event, menu) { _open: function(event, menu) {
if (this.active) { if (this.active) {
this.active.menu("closeAll").hide(); this.active.menu("closeAll").hide();
this.active.prev().removeClass("ui-state-active"); this.active.prev().removeClass("ui-state-active").removeAttr("tabIndex");
} }
var button = menu.prev().addClass("ui-state-active"); clearTimeout(this.timer);
this.open = true;
// set tabIndex -1 to have the button skipped on shift-tab when menu is open (it gets focus)
var button = menu.prev().addClass("ui-state-active").attr("tabIndex", -1);
this.active = menu.show().position({ this.active = menu.show().position({
my: "left top", my: "left top",
at: "left bottom", at: "left bottom",
Expand Down

0 comments on commit 4a04ad2

Please sign in to comment.