Skip to content

fix: prevent duplicate error message announcement when using NVDA - #3182

Merged
vursen merged 2 commits into
masterfrom
fix/prevent-double-error-announcement
Dec 13, 2021
Merged

vursen merged 2 commits into
masterfrom
fix/prevent-double-error-announcement

Conversation

@vursen

@vursen vursen commented Dec 13, 2021 •

Copy link
Copy Markdown
Contributor

Description

The PR introduces a workaround for FieldMixin that prevents double error message announcement when using NVDA, occurring as a side-effect of linking the error id to the ARIA target element. From now on, the error message is announced once and only when the [role=alert] attribute is added to the slotted error element.

The workaround is to add a setTimeout delay before linking the error id to the ARIA target element. This is the only workaround I was able to find. For the record, I tried requestAnimationFrame and new Promise((resolve) => resolve()), but they didn't work.

Fixes #3061

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@tomivirkki tomivirkki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that the change fixes the issue on NVDA. Didn't notice any regressions on other screen readers.

@vursen vursen changed the title fix: prevent double error message announcement in NVDA fix: prevent double error message announcement when using NVDA Dec 13, 2021
// 1. Once adding the `[role=alert]` attribute by the `_updateErrorMessage` method (OK).
// 2. Once linking the error ID with the ARIA target here (unwanted).
// Related issue: https://github.com/vaadin/web-components/issues/3061.
setTimeout(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Debouncer to handle case when field becomes invalid and then immediately valid.

@vursen vursen Dec 13, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking it over, I’m not sure if there is a real problem. The first callback will be postponed, but the possible second callback seems to be only executed after the first one because setTimeout(() => ..., 0) places the callback to the event loop queue that keeps the order.

The following test case passes even in the current implementation:

it('should not contain error id after consecutive invalid/valid', async () => {
  element.invalid = true;
  element.invalid = false;
  await aTimeout(0);
  const aria = input.getAttribute('aria-labelledby');
  expect(aria).to.include(label.id);
  expect(aria).to.include(helper.id);
  expect(aria).to.not.include(error.id);
});

@vursen
vursen merged commit 47b04f6 into master Dec 13, 2021
@vursen
vursen deleted the fix/prevent-double-error-announcement branch December 13, 2021 15:56
@vursen vursen changed the title fix: prevent double error message announcement when using NVDA fix: prevent duplicate error message announcement when using NVDA Dec 13, 2021
web-padawan pushed a commit that referenced this pull request Dec 13, 2021
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 23.0.0.alpha1 and is also targeting the upcoming stable 23.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVDA announces the field validation error twice

4 participants