Skip to content

Commit

Permalink
Add description for screen readers
Browse files Browse the repository at this point in the history
  • Loading branch information
otacke committed Nov 19, 2024
1 parent 2259962 commit 838839e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions language/.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@
},
{
"label": "Hide controls"
},
{
"label": "Description",
"description": "Provide a textual description of the animation which will be provided by screen readers."
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions language/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@
},
{
"label": "Verstecke Bedienelemente"
},
{
"label": "Beschreibung",
"description": "Gib eine textuelle Beschreibung der Animation an, die von Bildschirmlesern bereitgestellt wird."
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions semantics.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@
"type": "boolean",
"label": "Hide controls",
"default": false
},
{
"name": "description",
"type": "text",
"label": "Description",
"description": "Provide a textual description of the animation which will be provided by screen readers.",
"length": 5000
}
]
},
Expand Down
9 changes: 9 additions & 0 deletions src/scripts/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Toolbar from '@components/toolbar/toolbar.js';
import Timeline from '@models/timeline.js';
import Jukebox from '@services/jukebox.js';
import { MS_IN_S, secondsToMilliseconds, millisecondsToSeconds } from '@services/time-util.js';
import { decode } from 'he';
import './main.scss';

/** @constant {number} FRAMES_PER_SECOND Frames per second aspired. */
Expand Down Expand Up @@ -45,6 +46,14 @@ export default class AnimatorMain {
this.dom = document.createElement('div');
this.dom.classList.add('h5p-animator-main');

if (typeof this.params.description === 'string') {
const description = document.createElement('div');
description.classList.add('h5p-animator-description');
description.classList.add('sr-only');
description.textContent = decode(this.params.description);
this.dom.append(description);
}

this.canvas = new Canvas(
{
aspectRatio: this.params.aspectRatio,
Expand Down
12 changes: 12 additions & 0 deletions src/scripts/components/main.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.h5p-animator-main {
position: relative;

.sr-only {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
}
1 change: 1 addition & 0 deletions src/scripts/h5p-animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default class Animator extends H5P.EventDispatcher {
backgroundImage: this.retrieveBackgroundImage(
this.params.background.backgroundImage?.path, this.contentId
),
description: this.params.behaviour.description,
elements: this.retrieveElements(this.params.editor.elements),
dictionary: this.dictionary,
globals: this.globals,
Expand Down

0 comments on commit 838839e

Please sign in to comment.