diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-05-16 09:43:49 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-05-16 09:43:49 -0400 |
commit | 85639bf0fa39427d8de1dc60131f746045ba4ddc (patch) | |
tree | 2cbe8d2bef8e16c97568a7fb50ffbf59d641a78e /ui | |
parent | 5912d36374499e15d8d184df5ca122a4c4a4990f (diff) | |
download | jquery-ui-85639bf0fa39427d8de1dc60131f746045ba4ddc.tar.gz jquery-ui-85639bf0fa39427d8de1dc60131f746045ba4ddc.zip |
Autocomplete: Update live region if focus event is canceled. Remove live region on destroy.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index fa15bc278..1fc01d7a4 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -228,6 +228,13 @@ $.widget( "ui.autocomplete", { if ( /^key/.test(event.originalEvent.type) ) { this._value( item.value ); } + } else { + // Normally the input is populated with the item's value as the + // menu is navigated, causing screen readers to notice a change and + // announce the item. Since the focus event was canceled, this doesn't + // happen, so we update the live region so that screen readers can + // still notice the change and announce it. + this.liveRegion.text( item.value ); } }, menuselect: function( event, ui ) { @@ -261,6 +268,13 @@ $.widget( "ui.autocomplete", { } }); + this.liveRegion = $( "<span>", { + role: "status", + "aria-live": "polite" + }) + .addClass( "ui-helper-hidden-accessible" ) + .insertAfter( this.element ); + if ( $.fn.bgiframe ) { this.menu.element.bgiframe(); } @@ -284,6 +298,7 @@ $.widget( "ui.autocomplete", { .removeAttr( "aria-autocomplete" ) .removeAttr( "aria-haspopup" ); this.menu.element.remove(); + this.liveRegion.remove(); }, _setOption: function( key, value ) { @@ -530,24 +545,19 @@ $.extend( $.ui.autocomplete, { // live region extension, adding a `messages` option +// NOTE: This is an experimental API. We are still investigating +// a full solution for string manipulation and internationalization. $.widget( "ui.autocomplete", $.ui.autocomplete, { options: { messages: { noResults: "No search results.", results: function(amount) { - return amount + ( amount > 1 ? " results are" : " result is" ) + " available, use up and down arrow keys to navigate."; + return amount + ( amount > 1 ? " results are" : " result is" ) + + " available, use up and down arrow keys to navigate."; } } }, - _create: function() { - this._super(); - this.liveRegion = $( "<span>", { - role: "status", - "aria-live": "polite" - }) - .addClass( "ui-helper-hidden-accessible" ) - .insertAfter( this.element ); - }, + __response: function( content ) { var message; this._superApply( arguments ); |