Skip to content

Sparsely announce loading status to screen readers - #345

Merged
cdata merged 4 commits into
masterfrom
announce-loading-status
Feb 21, 2019
Merged

cdata merged 4 commits into
masterfrom
announce-loading-status

Conversation

@cdata

@cdata cdata commented Feb 8, 2019 •

Copy link
Copy Markdown
Contributor

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:

  • A singleton manages aggregation and observation of the loading state of all <model-viewer> instances that apply the LoadingMixin
  • <model-viewer> instances are observed when they connect to the document, and ignored after they disconnect
  • Two announcements are made: an initial one ("There are 3D models that are loading") and a final one ("All 3D models have loaded")
  • An initial announcement is made if (and only if) there is at least one <model-viewer> in the document
  • When all currently observed instances have either loaded or errored, the final announcement is made
  • Note: since the status announcer is bundled with the <model-viewer> implementation, at least one <model-viewer> must be upgraded and in the document for the initial to be made

Here is a demo of the behavior, using emulated network conditions ("Fast 3G" in DevTools):

announceloading

Fixes #301

@cdata
cdata force-pushed the announce-loading-status branch from 8b3f754 to cf9c06e Compare February 8, 2019 18:43
@cdata
cdata force-pushed the announce-loading-status branch 5 times, most recently from 4c6a658 to 2c96cfa Compare February 8, 2019 22:47
@cdata cdata changed the title (WIP) Sparsely announce loading status to screen readers Sparsely announce loading status to screen readers Feb 8, 2019
@cdata
cdata force-pushed the announce-loading-status branch from 2c96cfa to 5372f9a Compare February 8, 2019 22:55
@cdata
cdata requested review from jsantell and smalls February 8, 2019 23:25
smalls
smalls previously approved these changes Feb 11, 2019
*/
export class LoadingStatusAnnouncer {
/**
* The "status" instance is the <model-viewer> instance currently designated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bikeshed: I initially assumed that status meant something else, although this comment cleared it up for me.

Would "announcer" be clearer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was trying to stick to the ARIA terminology. I'll ponder changing it.

Comment thread src/test/helpers.js Outdated


/**
* Returns truu if the given element is in the tree of the document of the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be true, not truu.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

Comment thread src/test/helpers.js Resolved
jsantell
jsantell previously approved these changes Feb 11, 2019

@jsantell jsantell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could check loadShouldBeMeasured inside the promise, immediately resolving if needed rather than wrapping two Promise creators in a tertiary fn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

loadingStatusAnnouncer.registerInstance(elementOne);
loadingStatusAnnouncer.registerInstance(elementTwo);

await Promise.all(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await until(() => elementOne.loaded && elementTwo.loaded)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will fix

Comment thread src/utils.ts
// Stop iterating the Map with forEach:
throw new Error();
});
} catch (_error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😰 what a workaround!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bleeding-eyes.gif

readonly statusElement: HTMLParagraphElement = document.createElement('p');
protected statusUpdateInProgress: boolean = false;

protected[$updateStatus]: () => void =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just TypeScript speak for "doesn't return anything" (literally means returns undefined).

@cdata cdata Feb 13, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cdata cdata Feb 13, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts were that there were two important scenarios to cover:

  1. 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)
  2. 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):

  1. 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>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadAttemptComplete doesn't appear to be used as a member of InstanceLoadingStatus

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

const $updateStatus = Symbol('updateStatus');

interface InstanceLoadingStatus {
instanceWasUnregistered: () => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name was a bit confusing... onUnregister? cleanup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

*
* @see https://www.w3.org/TR/wai-aria-1.1/#status
*/
readonly statusElement: HTMLParagraphElement = document.createElement('p');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any browsers require any sort of element attributes before being used for ARIA props? (e.g. requires a minimum width/height or something)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll investigate this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadingStatusAnnouncer now inherits from EventDispatcher. The tests have been updated to listen to events rather than wait for a fixed amount of time.

@cdata
cdata dismissed stale reviews from jsantell and smalls via 7ce85a9 February 13, 2019 18:48
@googlebot

Copy link
Copy Markdown

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@google google deleted a comment from googlebot Feb 14, 2019
@cdata

cdata commented Feb 14, 2019

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

@cdata
cdata merged commit 6e8a31e into master Feb 21, 2019
@cdata
cdata deleted the announce-loading-status branch February 21, 2019 01:39
@elalish elalish mentioned this pull request Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants