design-system icon indicating copy to clipboard operation
design-system copied to clipboard

Inline error messages are dynamically appended, which breaks aria-live functionality

Open maggiewachs opened this issue 1 year ago • 1 comments

Describe the bug Our team is building a form with the CMS DS React components, and in testing we noticed that the inline error messages are not announced by a screen reader asynchronously or when focus is moved to the invalid field. It looks like the error markup is dynamically appended, in which case the aria-live region will not work. Live region markup needs to be rendered with the component: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions.

To Reproduce Steps to reproduce the behavior:

  1. Go to the Storybook page for the multiline text field: https://design.cms.gov/storybook/?path=/story/components-textfield--multiline-field
  2. Inspect the demo markup, and notice that there is no inline error message element in place
  3. In the "Controls" section, enter a value in the errorMessage field (hit "Set string" button, then use the text input)
  4. Inspect the markup again and see that the inline error element was appended (<p class="ds-c-inline-error"...>)

Expected behavior

  • The inline error message markup is rendered with the component markup and remains in place.
  • Only the inline error text value changes.

Screenshots Markup rendered with the component doesn't include the error element: image

The error element is dynamically appended when a text value is provided: image

Desktop (please complete the following information):

  • OS: Mac 14.5
  • Browser Chrome
  • Version 125.0.6422.78 (Official Build) (arm64)

Additional context The documentation page should include that the error mechanism uses aria-live (currently no mention of it): https://design.cms.gov/components/inline-error/?theme=core

maggiewachs avatar May 28 '24 16:05 maggiewachs

Thanks for flagging this. We're currently working on a wholistic pattern and guidance on form validation, so we'll make sure to address this in that set of changes.

pwolfert avatar May 28 '24 21:05 pwolfert

Closing issue. This was resolved in #3136

zarahzachz avatar Jul 15 '24 18:07 zarahzachz