简体   繁体   English

NVDA 未读出 trumbowyg 工具栏按钮的按下状态,但 VoiceOver 正在读出

[英]Pressed state of trumbowyg toolbar buttons not being read out by NVDA but are being read out by VoiceOver

I would like the pressed state of the trumbowyg toolbar buttons (bold/italic etc) to be read out by NVDA screen reader.我希望 trumowyg 工具栏按钮(粗体/斜体等)的按下状态由 NVDA 屏幕阅读器读出。 I have implemented the aria-pressed solution, which works fine for VoiceOver;我已经实现了 aria-pressed 解决方案,它适用于 VoiceOver; it reads out select/deselect when the buttons have been selected and deselected, however not for NVDA:它读出在选择和取消选择按钮时选择/取消选择,但不适用于NVDA:

function addValuesToTextEditorButtons() {
  const toggleButton = element => {
    // Check to see if the button is pressed
    var pressed = (element.getAttribute("aria-pressed") === "true");
    // Change aria-pressed to the opposite state
    element.setAttribute("aria-pressed", !pressed);
  }
  const handleBtnKeyDown = event => {
    // Prevent the default action to stop scrolling when space is pressed
    event.preventDefault();
    toggleButton(event.target);
  }

  var buttons = $('.trumbowyg-button-pane .trumbowyg-button-group button[type="button"]');
  buttons.each(function (index, element) {
    let title = element.title.split(' ')[0]
    element.value = title
    element.setAttribute('aria-label', title)
    element.setAttribute('aria-pressed', false)
    element.setAttribute('role', 'button')
    element.addEventListener('click', event => {
      handleBtnKeyDown(event)
    })  
    element.removeAttribute('tabindex')
  });
}

First off, verify that the element you're setting aria-pressed on is a real button (or role='button' ).首先,验证您设置aria-pressed的元素是一个真正的按钮(或role='button' )。 It looks like that's true from your code snippet but would be the first thing to verify.从您的代码片段来看,这似乎是正确的,但这将是要验证的第一件事。 ARIA attributes are only valid on certain elements. ARIA 属性仅对某些元素有效。 (See https://www.w3.org/TR/html53/dom.html#allowed-aria-roles-states-and-properties ) (见https://www.w3.org/TR/html53/dom.html#allowed-aria-roles-states-and-properties

Some screen readers might still announce the value of the attribute even if it's not valid so sometimes that explains why one SR works (such as VO) whereas another does not (NVDA).一些屏幕阅读器可能仍会宣布该属性的值,即使它无效,因此有时这解释了为什么一个 SR 有效(例如 VO)而另一个无效(NVDA)。

I've used aria-pressed successfully with all screen readers without a problem.我已经在所有屏幕阅读器上成功使用了aria-pressed ,没有任何问题。 For NVDA, it will announce the element as a " toggle button " and will say " pressed " or " not pressed " depending on the value.对于 NVDA,它会将元素声明为“切换按钮”,并会根据值说“已按下”或“未按下”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM