Skip to content

Commit 0b00c0e

Browse files
schanzermarijnh
authored andcommitted
Add role=presentation to more elements to help screenreaders
1 parent f583ab9 commit 0b00c0e

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/display/Display.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { gecko, ie, ie_version, mobile, webkit } from "../util/browser"
2-
import { elt } from "../util/dom"
2+
import { elt, eltP } from "../util/dom"
33
import { scrollerGap } from "../util/misc"
44

55
// The display handles the DOM integration, both for input reading
@@ -18,7 +18,7 @@ export function Display(place, doc, input) {
1818
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
1919
d.gutterFiller.setAttribute("cm-not-content", "true")
2020
// Will contain the actual code, positioned to cover the viewport.
21-
d.lineDiv = elt("div", null, "CodeMirror-code")
21+
d.lineDiv = eltP("div", null, "CodeMirror-code")
2222
// Elements are added to these to represent selection and cursors.
2323
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
2424
d.cursorDiv = elt("div", null, "CodeMirror-cursors")
@@ -27,10 +27,11 @@ export function Display(place, doc, input) {
2727
// When lines outside of the viewport are measured, they are drawn in this.
2828
d.lineMeasure = elt("div", null, "CodeMirror-measure")
2929
// Wraps everything that needs to exist inside the vertically-padded coordinate system
30-
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
30+
d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
3131
null, "position: relative; outline: none")
32+
let lines = eltP("div", [d.lineSpace], "CodeMirror-lines")
3233
// Moved around its parent to cover visible view.
33-
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative")
34+
d.mover = elt("div", [lines], null, "position: relative")
3435
// Set to the height of the document, allowing scrolling.
3536
d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
3637
d.sizerWidth = null

src/line/line_data.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getOrder } from "../util/bidi"
22
import { ie, ie_version, webkit } from "../util/browser"
3-
import { elt, joinClasses } from "../util/dom"
3+
import { elt, eltP, joinClasses } from "../util/dom"
44
import { eventMixin, signal } from "../util/event"
55
import { hasBadBidiRects, zeroWidthElement } from "../util/feature_detection"
66
import { lst, spaceStr } from "../util/misc"
@@ -64,14 +64,11 @@ export function buildLineContent(cm, lineView) {
6464
// The padding-right forces the element to have a 'border', which
6565
// is needed on Webkit to be able to get line-level bounding
6666
// rectangles for it (in measureChar).
67-
let content = elt("span", null, null, webkit ? "padding-right: .1px" : null)
68-
let builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content,
67+
let content = eltP("span", null, null, webkit ? "padding-right: .1px" : null)
68+
let builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
6969
col: 0, pos: 0, cm: cm,
7070
trailingSpace: false,
7171
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}
72-
// hide from accessibility tree
73-
content.setAttribute("role", "presentation")
74-
builder.pre.setAttribute("role", "presentation")
7572
lineView.measure = {}
7673

7774
// Iterate over the logical lines that make up this visual line.

src/model/mark_text.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { elt } from "../util/dom"
1+
import { eltP } from "../util/dom"
22
import { eventMixin, hasHandler, on } from "../util/event"
33
import { endOperation, operation, runInOp, startOperation } from "../display/operations"
44
import { clipPos, cmp, Pos } from "../line/pos"
@@ -166,8 +166,7 @@ export function markText(doc, from, to, options, type) {
166166
if (marker.replacedWith) {
167167
// Showing up as a widget implies collapsed (widget replaces text)
168168
marker.collapsed = true
169-
marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget")
170-
marker.widgetNode.setAttribute("role", "presentation") // hide from accessibility tree
169+
marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget")
171170
if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true")
172171
if (options.insertLeft) marker.widgetNode.insertLeft = true
173172
}

src/util/dom.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export function elt(tag, content, className, style) {
2929
else if (content) for (let i = 0; i < content.length; ++i) e.appendChild(content[i])
3030
return e
3131
}
32+
// wrapper for elt, which removes the elt from the accessibility tree
33+
export function eltP(tag, content, className, style) {
34+
let e = elt(tag, content, className, style)
35+
e.setAttribute("role", "presentation")
36+
return e
37+
}
3238

3339
export let range
3440
if (document.createRange) range = function(node, start, end, endNode) {

0 commit comments

Comments
 (0)