Repository navigation
Sparsely announce loading status to screen readers - #345
Conversation
8b3f754 to
cf9c06e
Compare
4c6a658 to
2c96cfa
Compare
2c96cfa to
5372f9a
Compare
| */ | ||
| export class LoadingStatusAnnouncer { | ||
| /** | ||
| * The "status" instance is the <model-viewer> instance currently designated |
There was a problem hiding this comment.
bikeshed: I initially assumed that status meant something else, although this comment cleared it up for me.
Would "announcer" be clearer?
There was a problem hiding this comment.
Ooh, I see - https://www.w3.org/TR/wai-aria-1.1/#status (linked below) gives a bit more context. I'll leave this comment here but I feel even less strongly about this bikeshed.
An idea might be "statusAnnouncer" or something, but that's cumbersome.
There was a problem hiding this comment.
Yeah, I was trying to stick to the ARIA terminology. I'll ponder changing it.
|
|
||
|
|
||
| /** | ||
| * Returns truu if the given element is in the tree of the document of the |
jsantell
left a comment
There was a problem hiding this comment.
Looks great! 👍 some nit alternative code lines, main thing I'm unsure about is restarting the debounce loop after it initially completes
| let instanceWasUnregistered = () => {}; | ||
| const loadShouldBeMeasured = | ||
| modelViewer.loaded === false && !!(modelViewer as any).src; | ||
| const loadAttemptCompletes = loadShouldBeMeasured ? |
There was a problem hiding this comment.
Could check loadShouldBeMeasured inside the promise, immediately resolving if needed rather than wrapping two Promise creators in a tertiary fn
| loadingStatusAnnouncer.registerInstance(elementOne); | ||
| loadingStatusAnnouncer.registerInstance(elementTwo); | ||
|
|
||
| await Promise.all( |
There was a problem hiding this comment.
await until(() => elementOne.loaded && elementTwo.loaded)
| // Stop iterating the Map with forEach: | ||
| throw new Error(); | ||
| }); | ||
| } catch (_error) { |
| readonly statusElement: HTMLParagraphElement = document.createElement('p'); | ||
| protected statusUpdateInProgress: boolean = false; | ||
|
|
||
| protected[$updateStatus]: () => void = |
There was a problem hiding this comment.
Is setting the output of debounce to void to ensure that it returns a void 0 value? Shouldn't this be invalid? Is this a typescript thing?
There was a problem hiding this comment.
This is just TypeScript speak for "doesn't return anything" (literally means returns undefined).
There was a problem hiding this comment.
BTW void is the implicit return signature for any function or method where a signature is not otherwise specified (I don't recall if TypeScript can infer from return in the body, but it does do fancy inference tricks elsewhere so who knows). You can omit it in many cases, but not if you are describing a return value type for a function that returns nothing (as we are doing here).
| this[$updateStatus](); | ||
| } | ||
|
|
||
| protected async updateStatus() { |
There was a problem hiding this comment.
IIUC, setting modelViewerStatusInstance starts the debounced polling, which only happens when an element is registered, and it's the first element to do so (when modelViewStatusInstance has not yet been created), and when an element is disconnected.
What of a scenario where n models are loaded, and later, a new model has been added, calling registerInstance, and then not starting the polling because modelViewerStatusInstance already exists? This could already be covered and I'm missing a piece, it looks like the last test could cover this, but I suspect both elements are registered immediately, while the initial debounce cycle is still running
There was a problem hiding this comment.
My thoughts were that there were two important scenarios to cover:
- First load of the page, where we will pick up N elements and then conclude when they have loaded (including lazily added ones in the mean time)
- The case where the site is a SPA, so a page navigation implies a new battery of elements might be added without having reset global state, but we should do the announcement flow over again
Notably this leaves out a third case (as I think you are pointing out):
- A
<model-viewer>is added after the final announcement, but before any of the previous<model-viewer>elements have been removed
This was done deliberately. My thinking here is that the risk of spammy loading announcements was a worse outcome than not saying anything about a sufficiently late-added <model-viewer>.
|
|
||
| interface InstanceLoadingStatus { | ||
| instanceWasUnregistered: () => void; | ||
| loadAttemptCompletes: Promise<any>; |
There was a problem hiding this comment.
loadAttemptComplete doesn't appear to be used as a member of InstanceLoadingStatus
| const $updateStatus = Symbol('updateStatus'); | ||
|
|
||
| interface InstanceLoadingStatus { | ||
| instanceWasUnregistered: () => void; |
There was a problem hiding this comment.
This name was a bit confusing... onUnregister? cleanup?
| * | ||
| * @see https://www.w3.org/TR/wai-aria-1.1/#status | ||
| */ | ||
| readonly statusElement: HTMLParagraphElement = document.createElement('p'); |
There was a problem hiding this comment.
I wonder if it'd be worthwhile for a singleton element somewhere outside of a element that could be used for any global interactions like this; reduce complexity, but of course, any changes to the DOM are unexpected, should be noted
There was a problem hiding this comment.
We took this approach with Polymer Elements in the past (see iron-a11y-announcer), and my opinion of it is that it is basically not good. Any time a component modifies the document outside of its shadow root, it risks running afoul of user expectations of how their document changes over time.
There is definitely room for a status announcer that is generalized for more than just loading status updates. But, I'm skeptical that we can generalize it beyond the domain of status announcements related to a specific custom element.
| debounce(() => this.updateStatus(), UPDATE_STATUS_DEBOUNCE_MS); | ||
|
|
||
| constructor() { | ||
| this.statusElement.setAttribute('role', 'status'); |
There was a problem hiding this comment.
Do any browsers require any sort of element attributes before being used for ARIA props? (e.g. requires a minimum width/height or something)
There was a problem hiding this comment.
Visibility is important. The element will probably be ignored if you use opacity: 0 or visibility: hidden, for example.
|
|
||
| await Promise.all( | ||
| [until(() => elementOne.loaded), until(() => elementTwo.loaded)]); | ||
| await timePasses(TIME_TO_UPDATE_MS); |
There was a problem hiding this comment.
This seems a bit fragile; similar to some of the async environment work, I wonder if we can expose some internal events for the debounce starting/stopping, similar to Model's envmap-change event, which is really only for tests.
There was a problem hiding this comment.
I'll investigate this
There was a problem hiding this comment.
LoadingStatusAnnouncer now inherits from EventDispatcher. The tests have been updated to listen to events rather than wait for a fixed amount of time.
Co-Authored-By: cdata <[email protected]>
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
@googlebot I signed it |
|
CLAs look good, thanks! |
This change proposes providing screenreader users with sparse updates on the current loading status of all
<model-viewer>elements on the page. Some details of the change:<model-viewer>instances that apply theLoadingMixin<model-viewer>instances are observed when they connect to the document, and ignored after they disconnect<model-viewer>in the document<model-viewer>implementation, at least one<model-viewer>must be upgraded and in the document for the initial to be madeHere is a demo of the behavior, using emulated network conditions ("Fast 3G" in DevTools):
Fixes #301