act*_*ram 7 ruby ruby-on-rails wai-aria
我正在尝试将aria-label属性添加到链接以使其更易于访问.当我这样做时,它按预期工作:
<a href="/" class="site-name <%= is_active('home') %>" aria-label="<%= get_aria_label_current_page('home') %>">Version Postman</a>
Run Code Online (Sandbox Code Playgroud)
但这不是:
<%= link_to t('nav.projects'), projects_path, class: is_active('projects'), aria-label: get_aria_label_current_page('home') %>
Run Code Online (Sandbox Code Playgroud)
我收到"意外的tLABEL"语法错误.谁知道问题是什么?
谢谢.
Mar*_*rez 13
这是创建问题的标签上的破折号.试试这个:
<%= link_to t('nav.projects'), projects_path, class: is_active('projects'), 'aria-label' => get_aria_label_current_page('home') %>
Run Code Online (Sandbox Code Playgroud)
更新
在ruby 2.2中你现在可以这样做:
'aria-label': get_aria_label_current_page('home')
Run Code Online (Sandbox Code Playgroud)
从至少Rails 5.2开始,它也可以工作:
<%= link_to t('nav.projects'),
projects_path,
class: is_active('projects'),
aria: { label: get_aria_label_current_page('home') } %>
Run Code Online (Sandbox Code Playgroud)
这类似于data-*属性的工作方式,这很好,因为您可以添加多个属性并将它们分组。
这可能适用于早期版本,但我尚未检查。