Skip to content

Commit 08ec7c2

Browse files
sach-gupta-21marijnh
authored andcommitted
[merge addon] Add aria-label for merge editor buttons and make them tabbable & keyboard interactive
1 parent 9545666 commit 08ec7c2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

addon/merge/merge.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
this.orig.state.trackAlignable = new TrackAlignable(this.orig)
4545
}
4646
this.lockButton.title = this.edit.phrase("Toggle locked scrolling");
47+
this.lockButton.setAttribute("aria-label", this.lockButton.title);
4748

4849
this.orig.state.diffViews = [this];
4950
var classLocation = options.chunkClassLocation || "background";
@@ -509,6 +510,8 @@
509510
copy.chunk = chunk;
510511
copy.style.top = (chunk.origTo > chunk.origFrom ? top : dv.edit.heightAtLine(chunk.editFrom, "local") - sTopEdit) + "px";
511512
copy.setAttribute("role", "button");
513+
copy.setAttribute("tabindex", "0");
514+
copy.setAttribute("aria-label", copy.title);
512515

513516
if (editOriginals) {
514517
var topReverse = dv.edit.heightAtLine(chunk.editFrom, "local") - sTopEdit;
@@ -520,6 +523,8 @@
520523
copyReverse.style.top = topReverse + "px";
521524
dv.type == "right" ? copyReverse.style.left = "2px" : copyReverse.style.right = "2px";
522525
copyReverse.setAttribute("role", "button");
526+
copyReverse.setAttribute("tabindex", "0");
527+
copyReverse.setAttribute("aria-label", copyReverse.title);
523528
}
524529
}
525530
}
@@ -602,20 +607,24 @@
602607
function buildGap(dv) {
603608
var lock = dv.lockButton = elt("div", null, "CodeMirror-merge-scrolllock");
604609
lock.setAttribute("role", "button");
610+
lock.setAttribute("tabindex", "0");
605611
var lockWrap = elt("div", [lock], "CodeMirror-merge-scrolllock-wrap");
606612
CodeMirror.on(lock, "click", function() { setScrollLock(dv, !dv.lockScroll); });
613+
CodeMirror.on(lock, "keyup", function(e) { e.key === "Enter" && setScrollLock(dv, !dv.lockScroll); });
607614
var gapElts = [lockWrap];
608615
if (dv.mv.options.revertButtons !== false) {
609616
dv.copyButtons = elt("div", null, "CodeMirror-merge-copybuttons-" + dv.type);
610-
CodeMirror.on(dv.copyButtons, "click", function(e) {
617+
function copyButtons(e) {
611618
var node = e.target || e.srcElement;
612619
if (!node.chunk) return;
613620
if (node.className == "CodeMirror-merge-copy-reverse") {
614621
copyChunk(dv, dv.orig, dv.edit, node.chunk);
615622
return;
616623
}
617624
copyChunk(dv, dv.edit, dv.orig, node.chunk);
618-
});
625+
}
626+
CodeMirror.on(dv.copyButtons, "click", copyButtons);
627+
CodeMirror.on(dv.copyButtons, "keyup", function(e) { e.key === "Enter" && copyButtons(e); });
619628
gapElts.unshift(dv.copyButtons);
620629
}
621630
if (dv.mv.options.connect != "align") {

0 commit comments

Comments
 (0)