vmware-archive / clarity

Clarity is a scalable, accessible, customizable, open source design system built with web components. Works with any JavaScript framework, built for enterprises, and designed to be inclusive.
http://clarity.design
MIT License
6.43k stars 760 forks source link

AriaLiveService is not announcing errors inside clrInputContainer #4222

Closed bdryanovski closed 4 years ago

bdryanovski commented 4 years ago

Describe the bug

clr-error when into the context of clr-input-container is rendered and then hidden. This is preventing AriaLiveService of updating and announcing the message inside the error. Also preventing the native angular lifecycles of firing.

How to reproduce

<clr-input-container>
  <label>Field 1 label</label>
  <input clrInput type="text" [(ngModel)]="fieldLabel" name="example" required />
  <clr-control-helper>Helper text that shows while it is pristine and valid</clr-control-helper>
  <clr-control-error>Error message that appears after focus is lost and control is invalid</clr-control-error>
</clr-input-container>

The only way to remove the aria-live DOM element is to detach clr-input-container from the DOM.

Content Projection is rendering the components before moving them inside the clr-input-container template. This is making some of the lifecycles behave in a strange way. For example onDestroy is not called when a component is hidden/shown with *ngIf. Angular is keeping the components alive until the parent is destroyed and reusing the same instance.

Expected behavior

Error content must be read from SR when it's rendered on the screen. As many times as the error happens.

Versions

All versions are affected.

Additional notes

A solution could be the use of ngTemplateOutlet but this will result in a breaking change. Another option could be providing a service that will provide both the container and the error with a message when the error is visible and when not, to force AriaLiveService to announce the message or remove it.

bdryanovski commented 4 years ago

With the deprecation of ClrAriaLiveService for internal use, we won't have this issue anymore

github-actions[bot] commented 4 years ago

Hi there 👋, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary.