jquery/jquery-ui — pull request #657 by jzaefferer (2012-05-15 12:08:58+00:00)
Title: Autocomplete: ARIA live region as extension, adding a messages option

Replacing #652

Starting this pull request to coordinate work between Everett, Hans, Scott and me (could also close this and put it on the wiki, though we should have more code soon). I've just spend a good amount of time reviewing the yahoo.com autocomplete, which is actually pretty similar to our approach. We figured that announcing only "autocomplete popup" is not useful. To make the announcements useful, it should be close to what yahoo.com is doing: "No search results available" or "x search results available, use up and down cursors to navigate". They don't set aria-activedescendent, so navigation gets announced properly as the input's value changes.

Here's a suggestion what the message format could look like:

```js
var defaults = {
messages: {
noresults: "No search results",
xresults: "$1 results available"
xresults: function(amount) {
return amount + " result" + (amount > 1 ? "s" : "") + " available, use up/down cursor...";
}
}
}

var de = {
messages: {
noresults: "Nichts gefunden",
xresults: function(amount) {
return amount + " Ergebnisse...";
}
}
}

xresults.replace("$1", amount)
```

If its a string, interpolate, if its a function, call it with all variables. That way we can allow simple interpolation where that's enough, and make it flexible enough to deal with more complex cases. Once Globalize adds support for this (https://github.com/jquery/globalize/issues/100), we can rip out the little custom code we'd require here and use Globalize instead.

The other change we should make is to extend menu to allow control over aria attributes. For autocomplete, we don't actually want any of them (see the yahoo.com example), just an unordered list. For Selectmenu, we want listbox and role option on the items.

This would make the autocomplete work in the current generation of screenreaders, following the more pragmatic approach that yahoo.com did on their homepage (not in YUI though). At the same time, we should get screenreader implementations to do more with the aria attributes for that. Currently aria-autocomplete and aria-owns are pretty much completely ignored. If that changes, we could get rid of the live region hack.