Skip to content

Commit 3b33901

Browse files
committed
Add support for alt+up/alt+down to expand/collapse. Don't expose dropdown arrow to assistive tech
1 parent 3053256 commit 3b33901

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/jquery.tagger.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@
281281
this.taggerSuggestionsButton = $('<div>')
282282
.addClass('droparrow')
283283
.addClass('hittarget')
284-
.attr('aria-label', 'Toggle option display')
285-
.attr('role', 'button')
286284
.bind('mouseup keyup', $.proxy(this._handleSuggestionsButtonInteraction, this))
287285
.appendTo(this.taggerButtonsPanel);
288286
$('<img>')
@@ -303,8 +301,6 @@
303301
.appendTo(this.taggerSuggestionsButton);
304302
}
305303

306-
this.taggerSuggestionsButton.attr("tabindex", this.tabIndex);
307-
308304
// Add placeholder text to text input field
309305
if (this.options.placeholder !== null) {
310306
this.taggerInput.attr("placeholder", this.options.placeholder);
@@ -325,6 +321,13 @@
325321
// Select the widget itself again
326322
this._getWidgetFocusable().focus();
327323
}
324+
325+
if (event.target && event.altKey && (event.which === this.keyCodes.DOWN || event.which === this.keyCodes.UP)) {
326+
this._toggleShowSuggestions();
327+
328+
// Select the widget itself again
329+
this._getWidgetFocusable().focus();
330+
}
328331
}, this));
329332

330333
// Capture the keypress event for any child elements - redirect any chars to the current input field
@@ -574,7 +577,7 @@
574577
}
575578
}
576579
else if (event.which === this.keyCodes.DOWN) { // Down Arrow
577-
if (isMainInput) {
580+
if (isMainInput && !event.altKey) {
578581
if (!this.options.ajaxURL || this.taggerSuggestions.is(":visible")) {
579582
this._showSuggestions(true);
580583
}
@@ -613,19 +616,28 @@
613616
this.taggerWidget.find("input[tabindex]:visible").first().focus();
614617
}
615618
else {
616-
// If the suggestion list is visible already, then toggle it off
617-
if (this.taggerSuggestions.is(":visible")) {
618-
this._hideSuggestions();
619-
}
620-
// otherwise show it
621-
else {
622-
this._showSuggestions(true);
623-
}
619+
this._toggleShowSuggestions();
624620
}
625621
event.preventDefault();
626622
}
627623
},
628624

625+
/**
626+
* Toggle whether suggestions are shown or not
627+
*
628+
* @private
629+
*/
630+
_toggleShowSuggestions: function() {
631+
// If the suggestion list is visible already, then toggle it off
632+
if (this.taggerSuggestions.is(":visible")) {
633+
this._hideSuggestions();
634+
}
635+
// otherwise show it
636+
else {
637+
this._showSuggestions(true);
638+
}
639+
},
640+
629641
/**
630642
* When keypress events fire on the tagger widget redirect them to the filter input
631643
*

0 commit comments

Comments
 (0)