Add "Accessibility" section to the explainer - #146
Conversation
| # EditContext API Explainer | ||
| ## Introduction | ||
| The EditContext is a new API that simplifies the process of integrating a web app with [advanced text input methods](#example-text-input-methods), improves accessibility and performance, and unlocks new capabilities for web-based editors. | ||
| The EditContext is a new API that simplifies the process of integrating a web app with [advanced text input methods](#example-text-input-methods), improves performance, and unlocks new capabilities for web-based editors. |
There was a problem hiding this comment.
I don't know if we want to lead with "improves accessibility" given that
- for canvas EditContext, the situation is not really any better than hidden contenteditable
- for non-canvas EditContext, it's not as if accessibility is "solved" by just switching to EditContext - the DOM contents still have to be made accessible
There was a problem hiding this comment.
Yeah I think this is a reasonable change.
dandclark
left a comment
There was a problem hiding this comment.
Thank for working on this, it's an important missing piece. What do you think about adding it as a non-normative section to the actual spec?
| # EditContext API Explainer | ||
| ## Introduction | ||
| The EditContext is a new API that simplifies the process of integrating a web app with [advanced text input methods](#example-text-input-methods), improves accessibility and performance, and unlocks new capabilities for web-based editors. | ||
| The EditContext is a new API that simplifies the process of integrating a web app with [advanced text input methods](#example-text-input-methods), improves performance, and unlocks new capabilities for web-based editors. |
There was a problem hiding this comment.
Yeah I think this is a reasonable change.
| For this reason, it is **not** exposed to assistive technologies such as screen readers. | ||
| So in order for an EditContext editor to be fully accessible, it must also render its contents in an accessible format to the DOM. | ||
|
|
||
| For all EditContext editors, the `aria-label` attribute should be set to a value which describes the purpose |
There was a problem hiding this comment.
The aria-label suggestion is probably correct, but is it specific to EditContext editors? I'm not sure it's more necessary here than for a general <div contenteditable> or <input>/<textarea>, so it might be misleading to call it out as something needed for EditContext in particular (although we could still show it in the example).
There was a problem hiding this comment.
Yes, that's true, although it's particularly important for <canvas> EditContext, since without the label, it gets announced as "image" to screen readers which is especially confusing. So I think it's worth saying it explicitly, although I'll make it clearer that it's not specific to EditContext.
| be set to `true` if the editor allows for more than one line of text. | ||
| The DOM contents of the editor should use the appropriate elements | ||
| and the appropriate ARIA attributes to communicate the semantics of the editor contents. | ||
| For example, `<p>` tags should be used for paragraphs, |
|
|
||
| This [example](native_selection_demo.html) shows how an author can leverage native selection when using EditContext. | ||
|
|
||
| ## Accessibility |
There was a problem hiding this comment.
I think we should consider adding this as a non-normative section to the spec instead of (or in addition to) the explainer. The spec has several examples already but unfortunately doesn't say much about accessibility.
There was a problem hiding this comment.
Sounds good! Maybe we can link to the spec from the explainer, so that we don't have the same information in multiple places, but people who only read the explainer will still see it?
| rendered to the canvas, to ensure that accessibility features which require the position of the text | ||
| work correctly (such as Windows Narrator highlighting the announced text). | ||
|
|
||
| ### Example: Accessibility for canvas EditContext |
There was a problem hiding this comment.
It would be nice to have an a11y expert review this, but I'm not sure who to recommend. I was also looking for something at https://www.w3.org/WAI/ARIA/apg/patterns/, but seems they chose not to include a rich text editor example: w3c/aria-practices#3310, w3c/aria-practices#88.
I'm still fine to move ahead with this for now though given the focus is more on "you'll have work to do to make this accessible" rather than "this the exact list of things you need to do to make this accessible."
There was a problem hiding this comment.
Yes, I'll try to see if we can get someone at Mozilla to take a look.
4eaf55e to
7479c4b
Compare
jcsteh
left a comment
There was a problem hiding this comment.
Thanks for working on this. I think this makes the accessibility situation much clearer.
| <p> | ||
| An EditContext's [=text=] useful for text input methods, | ||
| but since it is just a string, it cannot have any structure, such as paragraph divisions, | ||
| or interactive elements, such as hyperlinks and buttons. |
There was a problem hiding this comment.
I assume it also can't have formatting information; e.g. bold, emphasis, superscript, etc.? This is implied by text being a string, but it might be worth mentioning to further illustrate the point. (I see you do mention it later.)
| <p> | ||
| Just like with <code>contenteditable</code>, EditContext editors | ||
| should be given the attribute | ||
| <a href="https://w3c.github.io/aria/#textbox"><code>role="textbox"</code></a>, |
There was a problem hiding this comment.
role="textbox" isn't sufficient alone to expose the editable state which signals that something is an editor to some accessibility clients. This isn't an authoring concern, but somewhere, we'll need to specify what should signal to browsers to expose the editable state to accessibility clients. For example, here's where that is specified for contenteditable.
There was a problem hiding this comment.
I'll file a separate issue about it: #150
| When an EditContext is attached to a canvas, further care must be taken to ensure that the editor is accessible. | ||
| Alternative content must be provided for assistive technologies, using child elements of the canvas. | ||
| The selection in the EditContext must be kept in sync with the selection in the alternative content to ensure that assistive technologies work correctly. | ||
| Furthermore, the text in the alternative content should be in the same position on screen as the text |
There was a problem hiding this comment.
This is absolutely true. However, I'm fairly sure this isn't possible with any browser currently. Hit testing needs to be supported as well. I'm not sure whether either of these are feasible without changes to canvas; I suspect they aren't. I think this needs further investigation to determine whether this is even possible. If it isn't, that's a significant accessibility problem.
There was a problem hiding this comment.
I was thinking originally that the alternative content could be in a sibling element to prevent that kind of issue, but having the selection in a different place from the focus seems to cause even bigger problems. For what it's worth, descendants of canvas are still laid out (e.g. they have reasonable values for getBoundingClientRect) so I think it would just be a matter of making sure that information is exposed to accessibility, at least for a canvas with an attached EditContext. Not sure how feasible that is though. Maybe we can add a note about it in the spec for now.
There was a problem hiding this comment.
Hmm actually this does work properly in Firefox. Using Windows Narrator, the blue boxes are in the right place when narrating the EditContext text in the canvas EditContext demo I made. But it seems that Chromium and WebKit don't lay out canvas fallback content at all, unfortunately, although I'm not sure if this is specified anywhere.
There was a problem hiding this comment.
Interesting; I wasn't sure about that, though I did see some coordinates differing between paragraphs, so I did wonder. Note that even in Firefox, I'm fairly sure hit testing doesn't work (because that requires that the frames are included in display lists), even if bounding boxes do work. So this is definitely something that needs to be addressed in some way or another across all browsers.
| <p> | ||
| When an EditContext is attached to a canvas, further care must be taken to ensure that the editor is accessible. | ||
| Alternative content must be provided for assistive technologies, using child elements of the canvas. | ||
| The selection in the EditContext must be kept in sync with the selection in the alternative content to ensure that assistive technologies work correctly. |
There was a problem hiding this comment.
I think this is also true for DOM based EditContext editors. That is, it is not sufficient to "render its contents in an accessible format to the DOM"; the DOM selection needs to be kept in sync with EditContext. If that's already true by definition, please disregard, but I don't think it is.
There was a problem hiding this comment.
Yes, that's true. I think the original idea behind DOM-based EditContext was that the browser would manage the DOM selection (e.g. moving it with the arrow keys), and the web app would be responsible for updating the EditContext selection whenever the DOM selection changes (that's what the examples do). However in practice some EditContext users (namely Google Docs and the Monaco Editor) are just using it to receive text input, and render everything in a separate element. That's really not great for accessibility, so we should probably explicitly discourage it here.
There was a problem hiding this comment.
There's also a section entitled "Accessibility Issues in the Monaco Editor". Everything therein is true. However, I wanted to clarify: does EditContext definitely solve this? I guess with EditContext, the actual "rich view created from HTML" would be the focusable element with EditContext, so accessibility clients would be interacting directly with the rich HTML view instead of the textarea? Presumably, Monaco would need to keep the DOM selection in sync, etc.
There was a problem hiding this comment.
Yes, in theory it could improve the situation, if Monaco did let the browser manage the selection. Although it's a bit awkward to use that example when in fact Monaco isn't doing that, and so its EditContext implementation is not particularly accessible, as far as I can tell. So maybe it's best to remove that example.
There was a problem hiding this comment.
Given that this is an explainer, it seems reasonable that this could be used as a motivating example use case. However, given that it doesn't actually implement the fix, it might be appropriate to explain that EditContext could fix this (vs does fix it). For example, you could add something like the following paragraph to the bottom of that section:
With EditContext, use cases like this could be fixed by having the actual rich HTML view inside the EditContext element. This element would receive focus, so accessibility clients would be interacting directly with the real rich HTML view, rather than a separate, incomplete representation. The editor would need to ensure the DOM selection and caret were synchronized with the internal state and visual rendering of the editor.
There was a problem hiding this comment.
Or we could drop this example altogether, as you suggest. The above was just an alternative if there were any desire to keep mention of this example, not something I feel strongly about.
7479c4b to
d132db3
Compare
Fixes #136