Skip to content

Commit 5973b4f

Browse files
committed
Popup: Better key handling on trigger, along with a few more TODO comments
1 parent a2674a2 commit 5973b4f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/visual/menu/popup.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ $.widget( "ui.popup", {
3939
this._bind(this.options.trigger, {
4040
keydown: function( event ) {
4141
// prevent space-to-open to scroll the page, only hapens for anchor ui.button
42-
if ($( event.currentTarget ).is( "a:ui-button" ) && event.keyCode == $.ui.keyCode.SPACE) {
42+
if ( this.options.trigger.is( "a:ui-button" ) && event.keyCode == $.ui.keyCode.SPACE) {
4343
event.preventDefault()
4444
}
45-
// TODO handle keydown to open popup? only when not handled by ui.button
46-
//if (event.keyCode == $.ui.keyCode.SPACE) {
47-
//}
45+
// TODO handle SPACE to open popup? only when not handled by ui.button
46+
if ( event.keyCode == $.ui.keyCode.SPACE && this.options.trigger.is("a:not(:ui-button)") ) {
47+
this.options.trigger.trigger( "click", event );
48+
}
49+
// translate keydown to click
50+
// opens popup and let's tooltip hide itself
51+
if ( event.keyCode == $.ui.keyCode.DOWN ) {
52+
this.options.trigger.trigger( "click", event );
53+
}
4854
},
4955
click: function( event ) {
5056
event.preventDefault();
@@ -61,6 +67,7 @@ $.widget( "ui.popup", {
6167
});
6268

6369
this._bind(this.element, {
70+
// TODO use focusout so that element itself doesn't need to be focussable
6471
blur: function( event ) {
6572
var that = this;
6673
// use a timer to allow click to clear it and letting that
@@ -74,9 +81,11 @@ $.widget( "ui.popup", {
7481
this._bind({
7582
// TODO only triggerd on element if it can receive focus
7683
// bind to document instead?
84+
// either element itself or a child should be focusable
7785
keyup: function( event ) {
7886
if (event.keyCode == $.ui.keyCode.ESCAPE && this.element.is( ":visible" )) {
7987
this.close( event );
88+
// TODO move this to close()? would allow menu.select to call popup.close, and get focus back to trigger
8089
this.options.trigger.focus();
8190
}
8291
}
@@ -120,6 +129,7 @@ $.widget( "ui.popup", {
120129
.attr( "aria-hidden", false )
121130
.attr( "aria-expanded", true )
122131
.position( position )
132+
// TODO find a focussable child, otherwise put focus on element, add tabIndex=0 if not focussable
123133
.focus();
124134

125135
if (this.element.is(":ui-menu")) {

0 commit comments

Comments
 (0)