jquery - Typeahead and screenreaders -
i using typeahead/bloodhound generate list content of database. bloodhound suggestions read screenreader when highlighted. have added few aria roles elements in attempt content read screen reader. however, when highlighted, screenreader silent. if add focus element, blodhound modal window closes, not work.
what have far:
var mytypeahead = $('.supersearch').typeahead({ highlight: true, autoselect: true }, { name: 'search-content', displaykey: 'title', source: content.ttadapter(), templates:{ header: '<h3 class="typeaheadtitle">filtering content...</h3>', empty: [ '<div class="noresults">', 'no results', '</div>' ].join('\n'), suggestion: handlebars.compile('<div class="searchlistitem"><a href="{{link}}" class="searchlink" aria-label="{{title}}">{{title}}</a></div>') } }); mytypeahead.on('typeahead:cursorchanged', function($e, datum){ $(this).html(datum["value"]); var focused = $( document.activeelement ) var submenuhighlight = focused.parent().find('.tt-cursor .searchlistitem a'); console.log(submenuhighlight.text()); }); // add aria dialog role $('.tt-dataset-search-content').attr({ 'role': 'dialog', 'aria-live': 'assertive', 'aria-relevant':'additions' });
which adds aria label roles output list , container, in failed attempt notify reader list changes dynamically. listening cursorchanged, can isolate element need voiced (the console.log verifies this), not know how tell reader read current item tt-cursor class.
here html output:
<div class="tt-dataset-search-content" role="dialog" aria-live="rude" aria-relevant="additions"> <h3 class="typeaheadtitle">filtering content...</h3> <span class="tt-suggestions" style="display: block;"> <div class="tt-suggestion tt-cursor"> <div class="searchlistitem" style="white-space: normal;"> <a href="/about" class="searchlink" aria-label="about"><strong class="tt-highlight">a</strong>bout</a> </div> </div> <div class="tt-suggestion"> <div class="searchlistitem" style="white-space: normal;"> <a href="things" class="searchlink" aria-label="things">things</a> </div> </div>
all reader tells me when focused on input element is search field.
update
added fiddle: http://jsfiddle.net/m9a4sg52/
although dont think 1-1 setup, typeahead results generated after dom loads.
giving title highligted element might help.
mytypeahead.on('typeahead:cursorchanged', function($e, datum) { console.log($e); $(".tt-cursor").attr("title", datum); /* $(this).html(datum["value"]); var focused = $( document.activeelement ) var submenuhighlight = focused.parent().find('.tt-cursor .searchlistitem a'); console.log(submenuhighlight.text()); */ });
or why not adding custom template give title attribute 1 of this elements support title attribute.
Comments
Post a Comment