Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Merge pull request #52 from freckle/lucky/auto-activate-focus-mode-fo…
Browse files Browse the repository at this point in the history
…r-screen-readers

Auto activate focus mode for screen readers
  • Loading branch information
luckysoni authored Jan 25, 2023
2 parents 2748819 + eb30e62 commit d130229
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphy-js",
"version": "0.0.14",
"version": "0.0.15",
"author": {
"name": "Front Row Education",
"email": "[email protected]",
Expand Down
15 changes: 11 additions & 4 deletions src/helpers/paper-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ function speakPoint(point: PointT): string {
return `${Math.round(x)}, ${Math.round(y)}`
}

function announce(text: string) {
// used for aria-live announcements
const node = document.getElementById(ANNOUNCEMENT_NODE_ID)
if(node) {
node.innerText = text
}
}

type GroupKeyT
= 'grid'
| 'points'
Expand Down Expand Up @@ -237,16 +245,15 @@ const PaperUtil = {
this.pointsTool = new paper.Tool(pointsGroup)
this.pointsTool.activate()

// used for aria-live announcements
this.announcementNode = document.getElementById(ANNOUNCEMENT_NODE_ID)

// Provide keyboard accessible buttons for each
// dragable coordinate point on the graph
forEach(graphSettings.startingPoints, (p, index) => {
const controlButton = document.createElement('button')
const id = `control-button-${index}`
controlButton.id = id
controlButton.innerText = `Coordinates ${speakPoint(p)}.`
// auto-switch to focus mode for screen-readers
controlButton.setAttribute('role', 'application')
canvas.appendChild(controlButton)
const paperCenterPoint = this.fromGridCoordinateToView(p)
// round-robin colors
Expand Down Expand Up @@ -582,7 +589,7 @@ const PaperUtil = {

moveDraggedItemAt: (point: PointT): boolean => {
if (this.draggedItem) {
this.announcementNode.innerText = `Moved from coordinates (${speakPoint(this.fromViewCoordinateToGrid(this.draggedItem.position))}), to, coordinates ${speakPoint(point)}.`
announce(`Moved from coordinates (${speakPoint(this.fromViewCoordinateToGrid(this.draggedItem.position))}), to, coordinates ${speakPoint(point)}.`)
const paperPoint = this.fromGridCoordinateToView(point)
this.draggedItem.position = paperPoint
return true
Expand Down

0 comments on commit d130229

Please sign in to comment.