Skip to content

Commit 79bc8db

Browse files
jkunwarkunwarj
andauthored
Add Related Item button keyboard accessibility (#1259)
* make related item button keyboard accessible * open the related item option on enter press * hide the menu when focusout from add related items menu --------- Co-authored-by: Jagdish Kunwar <[email protected]>
1 parent 6d22be2 commit 79bc8db

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

nunaliit2-js/src/main/js/nunaliit2/n2.jquery.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ if( typeof $.widget === 'function' ){
112112
var text = this.element.find('option').first().text();
113113
this.button = $('<select>')
114114
.appendTo(this.wrapper)
115-
.mousedown(function(e){
115+
.on('mousedown', function(e) {
116116
_this._toggleMenu();
117117
return false;
118+
})
119+
.on('keydown', function(e) {
120+
if (e.key === 'Enter' || e.keyCode === 13) {
121+
_this._toggleMenu();
122+
return false;
123+
}
118124
});
119125
if( classes ){
120126
this.button.attr('class',classes);
@@ -130,9 +136,15 @@ if( typeof $.widget === 'function' ){
130136
.css('top','0px')
131137
.css('display','block')
132138
.css('z-index',1000)
139+
.attr('tabindex',0)
133140
.hide()
134141
.appendTo(this.wrapper);
135-
142+
143+
this.menu.on('focusout', function(e) {
144+
if (!_this.menu.has(e.relatedTarget).length) {
145+
_this.menu.hide();
146+
}
147+
});
136148
this.element.hide();
137149
}
138150

@@ -182,8 +194,10 @@ if( typeof $.widget === 'function' ){
182194
menu.empty();
183195
menu.hide();
184196
} else {
197+
menu.empty();
185198
this._createMenu(menu);
186199
menu.show();
200+
menu.find('a').attr('tabindex', 0);
187201
menu.position({
188202
my:'left top'
189203
,at: 'left bottom'

0 commit comments

Comments
 (0)