Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Alert screen reader users when content has been added (fixes #232) #233

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A sentence describing each fix

### Update
* A sentence describing each udpate
* A sentence describing each update

### New
* A sentence describing each new feature
Expand Down
18 changes: 9 additions & 9 deletions js/TrickleButtonModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ export default class TrickleButtonModel extends ComponentModel {
const text = (isDisabled && trickleConfig._button.disabledText) ?
trickleConfig._button.disabledText :
(isStart && trickleConfig._button.startText) ?
trickleConfig._button.startText :
(isFinal && trickleConfig._button.finalText) ?
trickleConfig._button.finalText :
trickleConfig._button.text;
trickleConfig._button.startText :
(isFinal && trickleConfig._button.finalText) ?
trickleConfig._button.finalText :
trickleConfig._button.text;

const ariaLabel = (isDisabled && trickleConfig._button.disabledAriaLabel) ?
trickleConfig._button.disabledAriaLabel :
trickleConfig._button.disabledAriaLabel :
(isStart && trickleConfig._button.startAriaLabel) ?
trickleConfig._button.startAriaLabel :
(isFinal && trickleConfig._button.finalAriaLabel) ?
trickleConfig._button.finalAriaLabel :
trickleConfig._button.ariaLabel;
trickleConfig._button.startAriaLabel :
(isFinal && trickleConfig._button.finalAriaLabel) ?
trickleConfig._button.finalAriaLabel :
trickleConfig._button.ariaLabel;

this.set({
buttonText: text,
Expand Down
25 changes: 23 additions & 2 deletions js/TrickleButtonView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Adapt from 'core/js/adapt';
import a11y from 'core/js/a11y';
import notify from 'core/js/notify';
import ComponentView from 'core/js/views/componentView';
import controller from './controller';
import {
Expand Down Expand Up @@ -118,7 +119,7 @@ class TrickleButtonView extends ComponentView {
this.$('.js-trickle-btn-container').toggleClass('u-display-none', isButtonHidden);
const isButtonDisabled = this.model.get('_isButtonDisabled');
const $button = this.$('.js-trickle-btn');
const $ariaLabel = this.$('.aria-label');
const $ariaLabel = this.$('.aria-label:not(.trickle__status)');
a11y.toggleEnabled($button, !isButtonDisabled);
if (!isButtonDisabled) {
// move focus forward if it's on the aria-label
Expand Down Expand Up @@ -202,10 +203,30 @@ class TrickleButtonView extends ComponentView {
*/
async continue() {
const parent = this.model.getParent();
await controller.continue();
const childrenAdded = await controller.continue();
if (!childrenAdded) return;
await this.announceContentLoaded();
await controller.scroll(parent);
}

/**
* Announce a message to screenreaders letting them know that additional
* content has been loaded on the page.
*/
async announceContentLoaded() {
const globals = Adapt.course.get('_globals');
const message = globals?._extensions?._trickle?.additionalContentLoaded;
if (!message) return;

notify.create({ _type: 'a11y-push', body: message });

// Rough estimate: 200ms per word + buffer
const words = message.split(' ').length;
const delay = (words * 200) + 300;
Copy link
Member

Choose a reason for hiding this comment

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

Happy with this? Did it all work as expected? Does it need a wider device test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works well except when using feedback popups. When you close the popup, the focus moves to the disabled Submit button and announces it. So, the "loading" message is spoken over and never heard.


return new Promise(resolve => setTimeout(resolve, delay));
}

tryButtonAutoHide() {
if (!this.model.get('_isButtonVisible')) return;
const trickleConfig = getModelConfig(this.model.getParent());
Expand Down
7 changes: 4 additions & 3 deletions js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ class TrickleController extends Backbone.Controller {
*/
async continue() {
applyLocks();
await Adapt.parentView.addChildren();
const addedCount = await Adapt.parentView.addChildren();
await Adapt.parentView.whenReady();
return addedCount;
}

/**
Expand Down Expand Up @@ -160,8 +161,8 @@ class TrickleController extends Backbone.Controller {

let scrollToId = getScrollToId();
if (!scrollToId) {
logging.error(`Cannot scroll to the next id as none was found at id: "${fromModel.get('_id')}" with _scrollTo: "${trickleConfig._scrollTo}". Suggestion: Set _showEndOfPage to false.`)
return
logging.error(`Cannot scroll to the next id as none was found at id: "${fromModel.get('_id')}" with _scrollTo: "${trickleConfig._scrollTo}". Suggestion: Set _showEndOfPage to false.`);
return;
}

const isDescendant = Adapt.parentView.model.getAllDescendantModels().some(model => {
Expand Down
10 changes: 10 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"inputType": "Text",
"validators": [],
"translatable": true
},
"additionalContentLoaded": {
"type": "string",
"required": true,
"title": "Additional content loaded.",
"default": "Loading.",
"inputType": "Text",
"help": "Announced to screen readers when additional content is loaded. Recommend keeping this short.",
"validators": [],
"translatable": true
}
},
"properties": {
Expand Down
9 changes: 9 additions & 0 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
"_adapt": {
"translatable": true
}
},
"additionalContentLoaded": {
"type": "string",
"title": "Additional content loaded",
"default": "Loading.",
"description": "Announced to screen readers when additional content is loaded. Recommend keeping this short.",
"_adapt": {
"translatable": true
}
}
}
}
Expand Down