Car*_*tes 11 jquery accessibility screen-readers typeahead.js bloodhound
我正在使用Typeahead/Bloodhound从数据库的内容生成列表.我希望屏幕阅读器在突出显示时能够阅读血腥建议.我在元素中添加了一些咏叹调角色,试图从屏幕阅读器中读取内容.但是,突出显示时,屏幕阅读器是静音的.如果我将焦点添加到元素,那么blodhound模态窗口将关闭,这将无法正常工作.
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'
});
Run Code Online (Sandbox Code Playgroud)
这会将aria标签角色添加到输出列表和容器,但尝试通知读者此列表动态更改.我也在听cursorchanged,所以我可以隔离我需要的元素(console.log验证这个),但我不知道如何告诉读者用tt-cursor类读取当前项.
<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>
</div>
Run Code Online (Sandbox Code Playgroud)
所有读者都告诉我,当关注输入元素时,它是一个搜索字段.
添加了一个小提琴:http://jsfiddle.net/m9a4sg52/
虽然我不认为这是一个1-1设置,因为在DOM加载后生成了预先输出结果.
为突出显示的元素赋予标题可能会有所帮助。
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());
*/
});
Run Code Online (Sandbox Code Playgroud)
或者为什么不添加自定义模板,然后将标题属性赋予支持标题属性的此元素之一。