react-aria-live icon indicating copy to clipboard operation
react-aria-live copied to clipboard

Support for message element?

Open thallada opened this issue 6 years ago • 6 comments

Hi, thanks for this project. I've struggled with aria-live regions in React before so I'm glad this exists. However, I can't use this library because PropTypes.string is the only allowable type to the message prop.

I need to have an element in the aria-live region. The main reason for this is because I need to wrap the text in a span that indicates the language of the text. E.g.:

<span lang="en">
  Hello, world!
</span>

This is because I use a translations service for all of the display strings in my application, and sometimes, some of the strings are not translated to the user's language. A screenreader needs to know the language of the string to read it out correctly.

I don't know about the internals of this library, but do you think it would be possible to make a change to support passing elements to the message prop (PropTypes.node is a great option for this)?

thallada avatar Jun 08 '18 20:06 thallada

Hi @thallada, thank you for your interest.

I am not yet convinced that this is something that should be solved by the ARIA live region.

Please help me understand more about what you are trying to achieve here. Why would a language tag be necessary here? If the <html> tag has the right language set I would only expect it to be set on other elements when a different language is used to the main one.

And these strings are being passed into the live region using user code, so this kinda looks like the moment to translate the message. Why can you not do it where the message originates?

I am bit loathe to inject more than strings into the live regions as it may lead to unexpected things if entire HTML contructs are allowed.

Let me know what you think.

AlmeroSteyn avatar Jun 09 '18 16:06 AlmeroSteyn

The case I'm thinking of is, for example:

  • the user's language preference is es
  • so, the root element gets the lang attribute: <html lang="es">
  • most of the display strings in the application are translated to es, except one
  • the display strings were originally written in en, so that one untranslated string defaults to en
  • in order for the screenreader to read that string out in English instead of Spanish, it needs to be wrapped in an element that has the attribute lang="en"

The way I've solved that case in my application is to just simply wrap every display string in a <span> that indicates the language.

I can't wrap <LiveMessage> in a span that indicates the language because the message actually gets rendered in a different part of the DOM.

I agree that it would be a lot simpler if LiveMessage only accepted strings, but I haven't found a better solution to this problem. It seems like others either translate their whole app or just ignore the few cases where the screenreader will read strings out wrong. WCAG 2.0 SC 3.1.2 covers this.

thallada avatar Jun 11 '18 16:06 thallada

I just realized there might be another option. If <LiveMessage> accepted a lang prop that would be rendered as an attribute on the MessageBlock div, that might also work.

That still wouldn't allow you to announce a message that contained more than one language, but that's a pretty unlikely edge case and one that my application doesn't need.

thallada avatar Jun 11 '18 16:06 thallada

Have not forgotten about this. Been a pretty busy time. Will get back to this soon.

AlmeroSteyn avatar Jul 06 '18 16:07 AlmeroSteyn

Once again circling back. Hope to get time for this soon. Feel free to submit a PR in the meantime.

AlmeroSteyn avatar Aug 03 '18 05:08 AlmeroSteyn

I can work on this, I might need this as well

dhovart avatar Dec 23 '20 22:12 dhovart