Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit d130229

Browse files
authored
Merge pull request #52 from freckle/lucky/auto-activate-focus-mode-for-screen-readers
Auto activate focus mode for screen readers
2 parents 2748819 + eb30e62 commit d130229

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphy-js",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"author": {
55
"name": "Front Row Education",
66
"email": "engineering@frontrowed.com",

src/helpers/paper-util.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ function speakPoint(point: PointT): string {
191191
return `${Math.round(x)}, ${Math.round(y)}`
192192
}
193193

194+
function announce(text: string) {
195+
// used for aria-live announcements
196+
const node = document.getElementById(ANNOUNCEMENT_NODE_ID)
197+
if(node) {
198+
node.innerText = text
199+
}
200+
}
201+
194202
type GroupKeyT
195203
= 'grid'
196204
| 'points'
@@ -237,16 +245,15 @@ const PaperUtil = {
237245
this.pointsTool = new paper.Tool(pointsGroup)
238246
this.pointsTool.activate()
239247

240-
// used for aria-live announcements
241-
this.announcementNode = document.getElementById(ANNOUNCEMENT_NODE_ID)
242-
243248
// Provide keyboard accessible buttons for each
244249
// dragable coordinate point on the graph
245250
forEach(graphSettings.startingPoints, (p, index) => {
246251
const controlButton = document.createElement('button')
247252
const id = `control-button-${index}`
248253
controlButton.id = id
249254
controlButton.innerText = `Coordinates ${speakPoint(p)}.`
255+
// auto-switch to focus mode for screen-readers
256+
controlButton.setAttribute('role', 'application')
250257
canvas.appendChild(controlButton)
251258
const paperCenterPoint = this.fromGridCoordinateToView(p)
252259
// round-robin colors
@@ -582,7 +589,7 @@ const PaperUtil = {
582589

583590
moveDraggedItemAt: (point: PointT): boolean => {
584591
if (this.draggedItem) {
585-
this.announcementNode.innerText = `Moved from coordinates (${speakPoint(this.fromViewCoordinateToGrid(this.draggedItem.position))}), to, coordinates ${speakPoint(point)}.`
592+
announce(`Moved from coordinates (${speakPoint(this.fromViewCoordinateToGrid(this.draggedItem.position))}), to, coordinates ${speakPoint(point)}.`)
586593
const paperPoint = this.fromGridCoordinateToView(point)
587594
this.draggedItem.position = paperPoint
588595
return true

0 commit comments

Comments
 (0)