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

Commit

Permalink
check element before calling method on it
Browse files Browse the repository at this point in the history
  • Loading branch information
luckysoni committed Jan 24, 2023
1 parent cc79f4f commit eb30e62
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 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,9 +245,6 @@ 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) => {
Expand Down Expand Up @@ -584,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 eb30e62

Please sign in to comment.